diff --git a/modules/ppcp-applepay/resources/js/ApplepayButton.js b/modules/ppcp-applepay/resources/js/ApplepayButton.js index 4f09d28d2..21b410427 100644 --- a/modules/ppcp-applepay/resources/js/ApplepayButton.js +++ b/modules/ppcp-applepay/resources/js/ApplepayButton.js @@ -150,13 +150,31 @@ class ApplePayButton { const idButton = this.buttonConfig.button.wrapper; if ( ! this.isEligible ) { - jQuery( '#' + idButton ).hide(); - jQuery( '#' + idMinicart ).hide(); - jQuery( '#express-payment-method-ppcp-applepay' ).hide(); + const hideContainers = [ + // Payment button (Pay now, smart button block) + `#${ idButton }`, + // Mini Cart button + `#${ idMinicart }`, + // Block Checkout: Express checkout button. + '#express-payment-method-ppcp-applepay', + ]; + + hideContainers.forEach( ( selector ) => { + const elements = document.querySelectorAll( selector ); + + elements.forEach( ( element ) => { + element.style.display = 'none'; + } ); + } ); return; } + // Classic Checkout: Make the Apple Pay gateway visible. + document + .querySelectorAll( 'style#ppcp-hide-apple-pay' ) + .forEach( ( el ) => el.remove() ); + // Add click-handler to the button. const setupButtonEvents = ( id ) => { document diff --git a/modules/ppcp-applepay/src/Assets/ApplePayButton.php b/modules/ppcp-applepay/src/Assets/ApplePayButton.php index d9a9d5393..22adce359 100644 --- a/modules/ppcp-applepay/src/Assets/ApplePayButton.php +++ b/modules/ppcp-applepay/src/Assets/ApplePayButton.php @@ -443,15 +443,15 @@ class ApplePayButton implements ButtonInterface { ) ); } else { - add_filter( - 'woocommerce_payment_successful_result', - function ( array $result ) use ( $cart, $cart_item_key ) : array { - $this->clear_current_cart( $cart, $cart_item_key ); - $this->reload_cart( $cart ); - return $result; - } - ); - } + add_filter( + 'woocommerce_payment_successful_result', + function ( array $result ) use ( $cart, $cart_item_key ) : array { + $this->clear_current_cart( $cart, $cart_item_key ); + $this->reload_cart( $cart ); + return $result; + } + ); + } } WC()->checkout()->process_checkout(); @@ -953,6 +953,7 @@ class ApplePayButton implements ButtonInterface { $render_placeholder, function () { $this->applepay_button(); + $this->hide_gateway_until_eligible(); }, 21 ); @@ -997,6 +998,19 @@ class ApplePayButton implements ButtonInterface { + +