Skip to content

Commit

Permalink
Check whether the dom elements exist before changing their attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
a-danae committed Nov 24, 2023
1 parent 646299c commit 863cfc7
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions client/classic/upe/payment-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,21 @@ function setSelectedUPEPaymentType( paymentType ) {

// Show or hide save payment information checkbox
function showNewPaymentMethodCheckbox( show = true ) {
if ( show ) {
document.querySelector(
'.woocommerce-SavedPaymentMethods-saveNew'
).style.visibility = 'visible';
} else {
document.querySelector(
'.woocommerce-SavedPaymentMethods-saveNew'
).style.visibility = 'hidden';
document
.querySelector( 'input#wc-stripe-new-payment-method' )
.setAttribute( 'checked', false );
document
.querySelector( 'input#wc-stripe-new-payment-method' )
.dispatchEvent( new Event( 'change' ) );
const saveCardElement = document.querySelector(
'.woocommerce-SavedPaymentMethods-saveNew'
);

if ( saveCardElement ) {
saveCardElement.style.visibility = show ? 'visible' : 'hidden';
}

const stripeSaveCardCheckbox = document.querySelector(
'input#wc-stripe-new-payment-method'
);

if ( ! show && stripeSaveCardCheckbox ) {
stripeSaveCardCheckbox.setAttribute( 'checked', false );
stripeSaveCardCheckbox.dispatchEvent( new Event( 'change' ) );
}
}

Expand Down

0 comments on commit 863cfc7

Please sign in to comment.