【问题标题】:Make checkout shipping postcode field not required in Woocommerce在 Woocommerce 中不需要结帐运输邮政编码字段
【发布时间】:2018-05-31 05:52:00
【问题描述】:

所以我按照Link 的说明更改邮政编码的必填字段。

add_filter( 'woocommerce_billing_fields', 'wc_optional_billing_fields' );
function wc_optional_billing_fields( $address_fields ) {
    $address_fields['shipping_postcode']['required'] = false;

    return $address_fields;
}

不幸的是,它没有更改 required ,而是创建了第二个字段: Image

谁能指出这里有什么问题?

【问题讨论】:

    标签: php wordpress woocommerce field checkout


    【解决方案1】:

    发生这种情况是因为您正在使用 woocommerce_billing_fields 挂钩过滤器,该过滤器仅管理 帐单字段 用于 shipping 邮政编码字段...

    您可以尝试使用woocommerce_shipping_fields 过滤钩子,但它不起作用,因为邮政编码 结帐字段是一个非常特殊字段,只能设置为不需要使用以下钩子函数:

    add_filter( 'woocommerce_default_address_fields', 'customise_postcode_fields' );
    function customise_postcode_fields( $address_fields ) {
        $address_fields['postcode']['required'] = false;
    
        return $address_fields;
    }
    

    如您所见,它同时作用于帐单和运输邮政编码字段。显然不可能只为账单和运输字段的运输邮政编码字段。

    官方文档教程:Customizing checkout fields using actions and filters

    【讨论】:

    • 啊,非常感谢您指出这一点,因为我也尝试了 woocommerce_billing_fields,但仍然无法正常工作!
    • @Exsedor 我已经尝试了所有可能的方法,唯一适合您情况的方法是我的答案中的方法……
    猜你喜欢
    • 2016-10-20
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    相关资源
    最近更新 更多