首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Woocommerce -根据计费国家/地区更改货币

Woocommerce -根据计费国家/地区更改货币
EN

Stack Overflow用户
提问于 2015-06-30 16:41:08
回答 1查看 1.5K关注 0票数 2

我正在尝试根据客户的账单国家/地区更改货币。当客户更改国家/地区时,是否可以通过覆盖"tax calculation“函数来完成此操作?

目前,我有这个函数(function.php):

代码语言:javascript
复制
add_filter('wcml_client_currency','change_currency');

function change_currency($client_currency){
   global $woocommerce;
   $country = $woocommerce->customer->get_country();
   if($country == 'CH') {
       $client_currency = 'CHF'; //currency code
   } else {
       $client_currency = 'EUR'; //currency code
   }
   return $client_currency;
}

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2018-03-13 18:39:49

您可以使用以下代码:

代码语言:javascript
复制
add_filter('woocommerce_get_price', 'return_custom_price', $product, 2);

function return_custom_price($price, $product) {    
global $post, $woocommerce;
$tot_qty = $woocommerce->cart->cart_contents_count;
// Array containing country codes
$county = array('NZ', 'AU', 'GB', 'IE');
// Amount to increase by
//$amount = 10;
change_existing_currency_symbol('NZD$', 'NZD');

if($woocommerce->customer->get_shipping_country() == 'NZ'){
    $amount = 0.00;
    $amount = 26.19;
}
else if($woocommerce->customer->get_shipping_country() == 'GB'){
    $amount = 0.00;
    $amount = 19.04;
}
else if($woocommerce->customer->get_shipping_country() == 'IE'){
    $amount = 0.00;
    $amount = 19.04;
}
else {
    $amount = 0.00;
    $amount = 28.19;
}

//echo $amount;
// If the custromers shipping country is in the array
if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ){
    // Return the price plus the $amount
   return $new_price = $amount;
   die();
} else {
    // Otherwise just return the normal price
    return $price;
    die();
}
}

add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);

function change_existing_currency_symbol( $currency_symbol, $currency ) {
    global $post, $woocommerce;
    $my_country = $woocommerce->customer->get_shipping_country();
     switch( $my_country ) {
          case 'GB': $currency_symbol = '£'; 
          break;

          case 'NZ': $currency_symbol = '$'; 
          break;

          case 'IE': $currency_symbol = '€'; 
          break;

          default:
                    $currency_symbol = '$'; 

     }
     return $currency_symbol;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31133501

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档