根据帐单所在国家/地区更改货币

问题描述 投票:0回答:1

我需要根据帐单国家/地区更改货币,使用以下代码可以以某种方式进行操作,但它仅适用于简单的产品,不适用于可变产品。

add_filter('woocommerce_get_price', 'return_custom_price', $product, 2);

function return_custom_price($price, $product) {    
    global $post, $woocommerce;
    
    // Array containing country codes
    $county = array('US');
    // Amount to increase by
    //$amount = 5;
    // If the custromers shipping country is in the array
    if ( in_array( $woocommerce->customer->get_billing_country(), $county ) && is_checkout() ){
        // Return the price plus the $amount
       return $new_price = ($price/260)*1.25;
    } else {
         
        // Otherwise just return the normal price
        return $price;
    }
} 
woocommerce hook-woocommerce
1个回答
0
投票

挂钩

woocommerce_get_price
自 WooCommerce 3 起已过时并已弃用,并已替换为以下挂钩:

  • woocommerce_product_get_price
    (针对产品)
  • woocommerce_product_variation_get_price
    (针对可变产品的变体)。

请参阅:通过 WooCommerce 3+ 中的挂钩更改产品价格

© www.soinside.com 2019 - 2024. All rights reserved.