2017-08-01 70 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文件中,或者也在任何插件文件中。