繁体   English   中英

使插件创建的自定义结帐必填字段在 WooCommerce 中可选

[英]Make custom checkout required field created by plugin optional in WooCommerce

在 woocommerce 结账页面需要去掉特定的自定义字段验证。 该字段基本上是由使用 woocommerce_form_field() 的插件生成的。有没有办法删除该特定字段的验证?这段代码块

echo '<div id="woo_delivery_delivery_selection_field" style="display:none;">';
            woocommerce_form_field('woo_delivery_delivery_selection_box',
            [
                'type' => 'select',
                'class' => [
                    'woo_delivery_delivery_selection_box form-row-wide'
                ],
                'label' => __($delivery_option_field_label, 'woo-delivery'),
                'placeholder' => __($delivery_option_field_label, 'woo-delivery'),
                'options' => Woo_Delivery_Delivery_Option::delivery_option($delivery_option_settings),
                'required' => true,
                'custom_attributes' => [
                    'data-no_result_notice' => __($no_result_notice, 'woo-delivery'),
                ],
            ], WC()->checkout->get_value('woo_delivery_delivery_selection_box'));
        echo '</div>'

您需要在您的functions.php中测试类似的代码。php 的子主题或活动主题


add_filter( 'woocommerce_checkout_fields', 'remove_validation_from_field', PHP_INT_MAX, 1 );
 
function remove_validation_from_field( $woo_checkout_fields_array ) {
    // use unset to remove the validation from your desired field
    // like I am removing the phone number validation from billing address
    unset( $woo_checkout_fields_array['billing']['billing_phone']['validate'] );
    return $woo_checkout_fields_array;
}
add_filter( 'woocommerce_checkout_fields' , 'woocommerce_form_fields' );
                
function  woocommerce_form_fields( $fields ) {
$fields['billing']['billing_first_name']['required'] = false;
return $fields;
}

实际上我们需要使用过滤钩 woocommerce_checkout_fields 并且需要根据帐单,运输,帐户,订单进行修改。 有关更多详细信息,您可以访问https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM