Check for WooCommerce error message and assign class to button text
-
add_action( 'wp_footer', 'custom_checkout_jquery_script' ); function custom_checkout_jquery_script() { if ( is_checkout() && ! is_wc_endpoint_url() ) : ?> <script type="text/javascript"> jQuery( function($){ jQuery('form.checkout').on('submit', function(event) { jQuery('button#place_order').text('Please Wait'); event.preventDefault(); }); }); //To detect woocommerce error trigger JS event jQuery( document.body ).on( 'checkout_error', function(){ console.warn("error occured!"); jQuery('button#place_order').text('Place Order'); } ); </script> <?php endif; }
Hi there,
does anyone know why isn’t this code able to check for the error message?
It’s replacing the “Place Order” text with “Please Wait” when clicked, and it’s supposed to revert the text back to “Place Order” if an error message is shown upon clicking the button by checking for the error message.
But the text won’t change back, if an error message is shown.
I would also like to change the class of text while the order is processing.
Can someone advise how to do that?Thanks in advance,
Adam
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Check for WooCommerce error message and assign class to button text’ is closed to new replies.