针对特定国家/地区的WooCommerce自定义本地化地址格式
我正在从WooCommerce打印地址标签,发现地址的换行符不是我所需要的.
I am printing address labels from WooCommerce and find that the line breaks for the addresses are not as I need them.
我在woocommerce_localisation_address_formats 钩子中找到了需要更改的代码,并添加了换行符,但是我不知道将正确的代码添加到功能文件中,因此避免了返回旧格式在下一次更新中.
I found the code I need to change in woocommerce_localisation_address_formats
hook and have added the line break but I do not know enough to add the correct code to the functions file thus avoiding going back to the old format on the next update.
这是更正的替换行:
'AU' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state} {postcode}\n{country}",
感谢您的帮助.
您需要使用 woocommerce_localisation_address_formats
过滤器钩子,如下所示:
You need to use woocommerce_localisation_address_formats
filter hook as follows:
add_filter( 'woocommerce_localisation_address_formats', 'filter_localisation_address_formats' );
function filter_localisation_address_formats( $address_formats ){
$address_formats['AU'] = "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state} {postcode}\n{country}";
return $address_formats;
}
代码进入活动子主题(或活动主题)的functions.php文件中.经过测试,可以正常工作.
Code goes in functions.php file of the active child theme (or active theme). Tested and works.