2017-08-01 73 views

回答

0

woocommerce中似乎有一个小错误。

然后,因为它的订购相关的电子邮件通知,您应该使用get_billing_country()WC_Order对象,而不是。

add_filter('woocommerce_order_get_billing_country','hook_order_get_billing_country', 10, 2); 
function hook_order_get_billing_country($value, $order){ 
    // Country codes/names 
    $countries_obj = new WC_Countries; 
    $country_array = $countries_obj->get_countries(); 
    // Get the country name from the country code 
    $country_name = $country_array[ $value ]; 
    // If country name is not empty we output it 
    if($country_name) 
     return $country_name; 
    // If $value argument is empty we get the country code 
    if(empty($value)){ 
     $country_code = get_post_meta($order->get_id(), '_billing_country', true); 
     // We output the country name 
     return $country_array[ $country_code ]; 
    } 
    return $value; 
} 

的代码放在您的活动子主题的function.php文件(或主题:

所以对于WC_Order对象get_billing_country()方法,这可以用下面依次绕来解决)或者在任何插件文件中。

代码进行测试和工程3+

所以现在你应该得到它的工作,并且输出正确的国名


随着WC_Customer对象有关wooCommerce版本get_billing_country()方法,你应该使用这个:

add_filter('woocommerce_customer_get_billing_country','wc_customer_get_billing_country', 10, 2); 
function wc_customer_get_billing_country($value, $customer){ 
    // Country codes/names 
    $countries_obj = new WC_Countries; 
    $country_array = $countries_obj->get_countries(); 
    // Get the country name from the country code 
    $country_name = $country_array[ $value ]; 
    // If country name is not empty we output it 
    if($country_name) 
     return $country_name; 
    // If $value argument is empty we get the country code 
    if(empty($value)){ 
     $country_code = get_user_meta($customer->get_id(), 'billing_country', true); 
     // We output the country name 
     return $country_array[ $country_code ]; 
    } 
    return $value; 
} 

该代码在你的活动子主题(或主题)的function.php文件中,或者也在任何插件文件中。