Hi @wp1605982g2n,
The checkout_error
is only triggered when the WC validation fails server side. That is not triggered during any client side validation which is what my plugin does. Your code would be much faster if you performed client side validations instead of submitting the form then returning a response and displaying the next step.
Anytime the value of a field inside the checkout form changes, the WooCommerce validat_field
function located in checkout.js
is called. If the field is invalid, it adds a class woocommerce-invalid
. Why not have your code check the fields for that class and if all fields in your section are valid, progress to the next step.
That will make your code faster.
Here you can see the credit card gateway performs validations when the place order button is clicked, or when the form submits and calls the .
https://plugins.trac.www.ads-software.com/browser/woo-stripe-payment/tags/3.2.15/assets/js/frontend/credit-card.js#L35
https://plugins.trac.www.ads-software.com/browser/woo-stripe-payment/tags/3.2.15/assets/js/frontend/credit-card.js#L224
It’s the code listening for the checkout_place_order_stripe_cc
event that is being triggered and performing the validation. If you really want to continue doing it the way you are, just change the value of the input name="payment_method" value="stripe_cc"
to some random gateway name like value="stripe_cc_waiting"
. And when all your steps and validations are complete you can change its value back to stripe_cc
. The reason this works is WC triggers an event checkout_place_order_${payment_method}
when the form is submitted. But if you have the html input’s value changed, it will not trigger the event that the credit card gateway is listening to.
Kind Regards,