【问题标题】:Disable billing_state field check out page WooCommerce禁用计费状态字段结帐页面 WooCommerce
【发布时间】:2020-10-21 09:22:16
【问题描述】:

我设法禁用了我的 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 字段上不起作用吗?也许与条件逻辑有关,因为 State 并不总是在您可以选择的所有国家/地区都可见?

【问题讨论】:

    标签: wordpress function woocommerce field checkout


    【解决方案1】:

    请尝试这样并在禁用之前设置默认国家/地区。您不能在没有任何值的情况下禁用必填字段。您还应该为下拉菜单设置国家/地区,并且要获得更多说明,您可以点击链接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;
        }`
    

    【讨论】:

    • 我想我误解了你的问题。所以请点击链接获取答案。 stackoverflow.com/questions/52279966/…
    • 感谢您的回答和链接以及这些功能我无法禁用 billing_state 字段...我可以禁用除此之外的所有字段:(
    猜你喜欢
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 2016-06-15
    相关资源
    最近更新 更多