Fix 'Invalid payment method' error upon double click 'Delete' #30862 (#30884)

* Fix 'Invalid payment method' error upon double click 'Delete' #30862

An 'Invalid payment method' error shows when a user double clicks the
'Delete' button in the 'Add Payment method screen'. Every time the user clicks
the button, there is a GET request to delete the payment method. First request is
handled correctly, but subsequent requests throw an error, because the payment
method cannot be found since it was already deleted.

This adds an event handler to disable the button on the first
click.

* Add changelog entry
This commit is contained in:
Miguel Gasca 2022-10-21 08:56:46 +02:00 committed by GitHub
parent 976e2f9e0b
commit c20f58e16a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix 'Invalid payment method' error upon double click on Delete button of Payment methods table

View File

@ -32,4 +32,13 @@ jQuery( function( $ ) {
$( document.body ).trigger( 'init_add_payment_method' );
// Prevent firing multiple requests upon double clicking the buttons in payment methods table
$(' .woocommerce .payment-method-actions .button.delete' ).on( 'click' , function( event ) {
if ( $( this ).hasClass( 'disabled' ) ) {
event.preventDefault();
}
$( this ).addClass( 'disabled' );
});
});