我不明白为什么get_billing_city()
方法不WC_emailcustomer_details()
方法工作,不像get_billing_country()
工作完美。获取WooCommerce订单结算城市电子邮件客户details.php电子邮件模板
如何使get_billing_city()
在WC_Email
customer_details()
方法努力得到email-customer-details.php
WooCommerce模板正确的输出?
我不明白为什么get_billing_city()
方法不WC_emailcustomer_details()
方法工作,不像get_billing_country()
工作完美。获取WooCommerce订单结算城市电子邮件客户details.php电子邮件模板
如何使get_billing_city()
在WC_Email
customer_details()
方法努力得到email-customer-details.php
WooCommerce模板正确的输出?
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文件中,或者也在任何插件文件中。