针对特定国家/地区的WooCommerce自定义本地化地址格式 [英] WooCommerce custom localization address format for specific country

查看:62
本文介绍了针对特定国家/地区的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.

这篇关于针对特定国家/地区的WooCommerce自定义本地化地址格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆