Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce checkout trigger validation of all fields

I am trying to trigger validation for the whole checkout form in woocommerce and do something based on having validation errors or not.

Unfortunately I didn't manage to do it. Anyone has any ideas?

EDIT: To be more specific, on submitting the woocommerce checkout form. I want to check if all the shipping fields are valid, but prevent submitting the form because I want to process that form data further (but only if it's valid).

like image 681
heraphim Avatar asked Nov 15 '25 12:11

heraphim


1 Answers

great hints in the comments. Here is the actual working code, to save some time for future people:

// Trigger the validation of the fields (you can adjust and pick which fields are validated)    
jQuery('.validate-required input, .validate-required select').trigger('validate');

// Get which fields have failed validation
jQuery('.woocommerce-invalid-required-field').each(function(index, element){
    console.log(element.id)
})
like image 178
kioleanu Avatar answered Nov 18 '25 19:11

kioleanu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!