Refactor event listener setup for place order button

This commit is contained in:
Daniel Hüsken 2024-11-18 14:49:03 +01:00
parent b8e85fe3f2
commit c1dbb83350
No known key found for this signature in database
GPG key ID: 9F732DA37FA709E8

View file

@ -82,9 +82,8 @@ import {
renderFields( cardFields );
}
document
.querySelector( '#place_order' )
?.addEventListener( 'click', ( event ) => {
const placeOrderButton = document.querySelector( '#place_order' );
placeOrderButton?.addEventListener( 'click', ( event ) => {
const cardPaymentToken = document.querySelector(
'input[name="wc-ppcp-credit-card-gateway-payment-token"]:checked'
)?.value;
@ -95,11 +94,11 @@ import {
) {
return;
}
document.getElementById('place_order').disabled = true;
placeOrderButton.disabled = true;
event.preventDefault();
cardFields.submit().catch( ( error ) => {
console.error( error );
document.getElementById('place_order').disabled = false;
placeOrderButton.disabled = false;
} );
} );
} );