在我的设计中,我有非标准计费字段标签和标记。例如,“城镇/城市*”应为“省*”。
我使用过WOO文档,并过滤woocommerce_billing_fields
。它适用于类名、占位符、创建新字段。但我无法更改标签。
$out_arr['billing_city']['class'][0] = 'form-row-first';
$out_arr['billing_city']['label'] = __('Province', 'woocommerce');
$out_arr['billing_postcode']['label'] = __('Zipcode', 'woocommerce');
并使用var_dump
of new $out_arr
数组它显示正确的标签
["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"
}
但我的前端仍然有旧标签。请问有什么建议吗?
在特定情况下你需要使用woocommerce_default_address_fields
筛选。此过滤器适用于所有计费和运输默认字段:
'country'
, 'first_name'
, 'last_name'
, 'company'
, 'address_1'
, 'address_2'
, 'city'
, 'state'
or 'postcode'
.
这里我们只使用'city'
and 'postcode'
如您的代码中所示:
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 文件中
参考:
- OfficialWooThemes - 使用操作和过滤器自定义结账字段
- WooCommerce - 覆盖现有结账字段上的账单状态和邮政编码
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)