skip to Main Content

In woocommerce checkout page need to remove a specific custom field validation. This field is basically generated by a plugin using woocommerce_form_field().Is there any way to remove the validation for that specific field?The piece of code block

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>'

2

Answers


  1. you need to test the code like it into your functions.php of child or active theme


    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;
    }
    
    Login or Signup to reply.
  2. add_filter( 'woocommerce_checkout_fields' , 'woocommerce_form_fields' );
                    
    function  woocommerce_form_fields( $fields ) {
    $fields['billing']['billing_first_name']['required'] = false;
    return $fields;
    }
    

    Actually we need use filter hook woocommerce_checkout_fields and need to modified based on billing,shiping,account,orders.
    For more details you may visit https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
    thank you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search