stosun
stosun

Reputation: 21

How Remove Required Validation at Conditional Checkout Field at Woocommerce

I use conditional checkout fields as given at Conditionally unset checkout field in woocommerce . But, It doesn't remove required validation fields? How can I pass conditional statement within "if (true)" to remove required validation ? At the other words, how can I check which option is selected? Regards

 if( true ){ // pass conditional statement here
     unset($fields['billing']['add_house_name']);  //  remove field
     $fields['billing']['add_building_name']['required']   = false; //            remove required validation
        }                   
        return $fields;

Upvotes: 1

Views: 4584

Answers (1)

Vidish Purohit
Vidish Purohit

Reputation: 1078

You can override checkout fields using this code:

// Hook in
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );

// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
     $address_fields['address_1']['required'] = false;

     return $address_fields;
}

You can add this hook to a condition where you check inputs based on which you want to trigger validation.

Upvotes: 1

Related Questions