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).
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)
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.