Reputation: 346
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).
Upvotes: 4
Views: 3900
Reputation: 947
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)
})
Upvotes: 3