wordpress - 禁用 billing_state 字段签出页面 WooCommerce
问题描述
我设法禁用了我的 WooCommerce 网上商店中的每个结帐字段,但由于某些奇怪的原因,只有“billing_state”不起作用。
这些是我正在使用的钩子
add_filter( 'woocommerce_checkout_fields' , 'custom_checkout_fields' );
function custom_checkout_fields( $fields ) {
$fields['billing']['billing_postcode']['custom_attributes']['disabled'] = 'disabled';
$fields['billing']['billing_city']['custom_attributes']['disabled'] = 'disabled';
$fields['billing']['billing_state']['custom_attributes']['disabled'] = 'disabled';
return $fields;
}
我也已经尝试过 billing_country 字段,因为这也是一个选择字段,也许它与此有关,但在 billing_country 字段上,代码工作正常。
任何人都知道为什么此功能在结帐时对我的 billing_state 字段不起作用?也许与条件逻辑有关,因为您可以选择的所有国家/地区并不总是可见状态?
解决方案
请尝试这样并在禁用之前设置默认国家/地区。您不能在没有任何值的情况下禁用必填字段。您还应该为下拉菜单设置国家/地区,为了更清楚,您可以点击链接Make checkout country dropdown readonly in Woocommerce
add_filter('woocommerce_checkout_fields', 'readdonly_country_select_field');
function readdonly_country_select_field( $fields ) {
// Set billing and shipping state to AU
WC()->customer->set_billing_state('state');
// Make billing and shipping country field read only
$fields['billing']['billing_state']['custom_attributes'] = array( 'disabled' => 'disabled' );
return $fields;
}`
推荐阅读
- python - 计算检测到的对象像素数占图片总像素数的百分比
- swift - 使用 Any 而不是泛型
- docker - 如何配置 docker-compose 卷访问权限
- database - MongoDB WiredTiger 是否使用聚集索引?
- android - Kotlin,警报管理器不触发
- javascript - 如何使用 JavaScript 更改对象中的项目以替换 Firebase 不接受的特殊字符
- android - 如何从 SQLite 数据库中检索声音?
- mysql - MySQL:计算列中的宽度日期
- javascript - NodeJs Express - 如何返回 HTTP 错误代码 (400,401,500) 和 JSON 对象
- javascript - jQuery 读取 .txt 文件但获取特定数据