首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >禁用billing_state字段签出页面WooCommerce

禁用billing_state字段签出页面WooCommerce
EN

Stack Overflow用户
提问于 2020-10-21 17:22:17
回答 1查看 259关注 0票数 0

我设法禁用了我的WooCommerce网上商店中的每个结帐字段,但由于某种奇怪的原因,只有"billing_state“不起作用。

这些是我正在使用的钩子

代码语言:javascript
复制
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字段,因为这也是一个select字段,也许它与此有关,但是在billing_country字段上,代码工作得很好。

有没有人知道为什么这个函数在结帐时对我的billing_state字段不起作用?可能与条件逻辑有关,因为State并不总是对您可以选择的所有国家都可见?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-21 20:56:15

请尝试此操作并设置默认国家/地区,然后再将其禁用。您不能在没有任何value.You的情况下禁用必填字段,还应为下拉菜单设置国家,有关更多说明,请访问链接Make checkout country dropdown readonly in Woocommerce

代码语言:javascript
复制
    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;
    }`
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64460530

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档