Why won’t this code revert the button text back to Place Order if an error message is triggered?
The text was changed upon clicking the button, which works fine.
But it should change back if an error message occurs upon clicking the button.
There are no console messages for the error.
This is a Stripe payment button, it’s Woocommerce.
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(){
var wooError = $('.woocommerce-error');
jQuery('button#place_order').text('Place Order');
} );
</script>
<?php
endif;
}