在WooCommerce email-customer-details.php电子邮件模板中获取订单计费城市
我不明白为什么在WooCommerce email-customer-details.php电子邮件模板中获取订单计费城市,php,wordpress,woocommerce,orders,email-notifications,Php,Wordpress,Woocommerce,Orders,Email Notifications,我不明白为什么get\u billing\u city()方法在WC\u电子邮件中不起作用
get\u billing\u city()
方法在WC\u电子邮件中不起作用
方法不同于get\u billing\u country()
方法工作得很好
如何使
在WC_Email
客户详细信息()中使用方法以在电子邮件客户详细信息中获得正确的输出。php
WooCommerce模板?看起来WooCommerce中有一个小漏洞
然后,由于它是一个与订单相关的电子邮件通知,您应该使用带有WC\u Order
对象的get\u billing\u country()
方法
因此,对于WC\u Order
对象get\u billing\u country()
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文件或任何插件文件中
代码经过测试,适用于wooCommerce版本3+
因此,现在您应该让它工作并输出正确的国家名称
使用WC\u Customer
对象关于获取计费国家/地区()
方法,您应该使用以下方法:
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文件中,或者出现在任何插件文件中。看起来woocommerce中有一个小bug
然后,由于它是一个与订单相关的电子邮件通知,您应该使用带有WC\u Order
对象的get\u billing\u country()
方法
因此,对于WC\u Order
对象get\u billing\u country()
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文件或任何插件文件中
代码经过测试,适用于wooCommerce版本3+
因此,现在您应该让它工作并输出正确的国家名称
使用WC\u Customer
对象关于获取计费国家/地区()
方法,您应该使用以下方法:
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文件或任何插件文件中