如何在WooCommerce中更改帐单邮寄地址字段标签 [英] How to change Billing address field label in WooCommerce
问题描述
在我的设计中,我有非标准的帐单字段标签和标记.例如,市镇*"应为省*".
In my design i have non standard billing fields label and markup. For example "Town / City *" should be "Province *".
我使用过WOO文档,并过滤了 woocommerce_billing_fields
.它可以与类名,占位符一起使用,创建新字段.但是我无法达到更改的标签.
I have used WOO documentation, and filter woocommerce_billing_fields
. And it works with class name, placeholder, create new fields. But I cant reach label changed.
$out_arr['billing_city']['class'][0] = 'form-row-first';
$out_arr['billing_city']['label'] = __('Province', 'woocommerce');
$out_arr['billing_postcode']['label'] = __('Zipcode', 'woocommerce');
并使用新的 $ out_arr
数组的 var_dump
,它显示正确的标签
and using var_dump
of new $out_arr
array it shows correct labels
["billing_city"]=>
array(4) {
["label"]=>
string(8) "Province"
["required"]=>
bool(true)
["class"]=>
array(2) {
[0]=>
string(14) "form-row-first"
[1]=>
string(13) "address-field"
}
["autocomplete"]=>
string(14) "address-level2"
}
但是我在前端仍然有旧标签.有什么建议吗?
But i still have old labels in front-end. Any suggestions please?
推荐答案
在特定情况下,您需要使用 woocommerce_default_address_fields
过滤器.此过滤器适用于所有结算和发货默认字段:'国家/地区'
,'姓氏'
,'last_name'
,'company'
,'address_1'
,'address_2'
,'city'
,'state'
或'postcode'
.
In specific cases you need to use the woocommerce_default_address_fields
filter. This filter is applied to all billing and shipping default fields:
'country'
, 'first_name'
, 'last_name'
, 'company'
, 'address_1'
, 'address_2'
, 'city'
, 'state'
or 'postcode'
.
此处,我们仅在您的代码中使用 'city'
和 'postcode'
:
Here we only use 'city'
and 'postcode'
as in your code:
add_filter( 'woocommerce_default_address_fields' , 'override_default_address_fields' );
function override_default_address_fields( $address_fields ) {
// @ for city
$address_fields['city']['class'] = array('form-row-first');
$address_fields['city']['label'] = __('Province', 'woocommerce');
// @ for postcode
$address_fields['postcode']['label'] = __('Zipcode', 'woocommerce');
return $address_fields;
}
这已通过测试并且可以正常工作.
此代码段位于您的活动子主题或主题的function.php文件中
参考文献:
- Official WooThemes - Customizing checkout fields using actions and filters
- WooCommerce - Overriding billing state and post code on existing checkout fields
这篇关于如何在WooCommerce中更改帐单邮寄地址字段标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!