在我的设计中,我有非标准的结算字段标签和标记 . 例如,“城镇/城市*”应为“省*” .
我使用过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
的新 $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"
}
但我仍然在前端有旧标签 . 有什么建议吗?
2 回答
In specific cases 您需要使用 woocommerce_default_address_fields 过滤器 . 此过滤器适用于所有结算和发货默认字段:
'country'
,'first_name'
,_ 27101020,'company'
,'address_1'
,_ 27101023,'city'
,'state'
或'postcode'
.在这里,我们只在您的代码中使用 'city' 和 'postcode' :
This is tested and working.
此代码段位于您的活动子主题或主题的function.php文件中
参考文献:
Official WooThemes - Customizing checkout fields using actions and filters
WooCommerce - Overriding billing state and post code on existing checkout fields
它涉及编码,在我看来,这使得事情变得更容易 . 这是插件 Booster for WooCommerce .
它还宣传了我尚未尝试的其他几种定制可能性,但调整标签的工作正常 .
顺便说一句,根据您的服务器设置,它可能会在激活时导致内存不足错误,WordPress会返回一个空白页面 . 临时增加分配给PHP的内存允许它完成激活 .