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



我正试图根据客户的计费国家/地区更改货币。是否可以通过覆盖"税务计算"功能来做到这一点,因为当客户更改国家/地区时,该功能会更新?

目前,我有这个函数(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;
}

谢谢你的帮助。

您可以使用以下代码:

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

最新更新