【发布时间】:2020-10-10 15:49:33
【问题描述】:
我正在尝试删除或增加我使用 Woocommerce 开发的 WordPress 网站上的默认最大长度(现在设置为 4)。
到目前为止,我已经在我的 childtheme 的 functions.php 上尝试了所有这些功能
#选项 1
function wpse215677_checkout_fields ( $fields ) {
$fields['postcode']['maxlength'] = 5;
return $fields;
}
add_filter('woocommerce_default_address_fields', 'wpse215677_checkout_fields');
#OPTION 2 - 有和没有 ['custom_attributes']
add_filter( 'woocommerce_checkout_fields' , 'my_override_checkout_fields');
function my_override_checkout_fields( $fields ) {
$fields['billing']['postcode']['custom_attributes']['maxlength'] = 5;
$fields['billing']['billing_postcode']['custom_attributes']['maxlength'] = 5;
return $fields;
}
#OPTION 3 - 有和没有 ['custom_attributes']
function my_wc_custom_billing_fields( $fields ) {
$fields['billing_postcode']['custom_attributes']['maxlength'] = 5;
return $fields;
}
add_filter( 'woocommerce_billing_fields', 'my_wc_custom_billing_fields' );
function my_wc_custom_shipping_fields( $fields ) {
$fields['shipping_postcode']['custom_attributes']['maxlength'] = 5;
return $fields;
}
add_filter( 'woocommerce_shipping_fields', 'my_wc_custom_shipping_fields' );
所有这些都在购物车计算器上运行良好(现在我可以写任何超过 4 的数字)但是当我转到结帐页面并尝试在邮政编码(运输或账单)上写一个超过 4 个字符的数字时,输入仍然保持最大长度为 4(我已经使用 Chrome 的工具对其进行了检查)。
有什么方法可以覆盖结帐时的整个输入,以允许我在此输入上写入超过 4 个字符?
或者我对这些功能做错了什么,这就是为什么它们在结帐页面上不起作用?
【问题讨论】:
标签: php wordpress woocommerce checkout maxlength