【问题标题】:Woocommerce - Change currency depending on billing countryWoocommerce - 根据帐单国家/地区更改货币
【发布时间】:2018-03-13 18:39:48
【问题描述】:

我正在尝试根据客户的帐单国家/地区更改货币。是否可以通过覆盖“税收计算”功能来做到这一点,因为它会在客户更改国家/地区时更新?

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

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;
}

感谢您的帮助。

【问题讨论】:

  • 你找到解决办法了吗?

标签: php wordpress woocommerce


【解决方案1】:

您可以使用以下代码:

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;
}

【讨论】:

    猜你喜欢
    • 2015-05-10
    • 2013-08-18
    • 1970-01-01
    • 2017-02-08
    • 2016-01-01
    • 2019-08-07
    • 2021-04-24
    • 2020-07-26
    • 1970-01-01
    相关资源
    最近更新 更多