diff --git a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js index 59e511a43..8b5dcd3e9 100644 --- a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js +++ b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js @@ -113,6 +113,13 @@ export default class PaymentButton { */ #isInitialized = false; + /** + * Whether the one-time initialization of the payment gateway is complete. + * + * @type {boolean} + */ + #gatewayInitialized = false; + /** * The button's context. * @@ -715,26 +722,34 @@ export default class PaymentButton { } /** - * Makes the custom payment gateway visible by removing initial inline styles from the DOM. + * Makes the payment gateway visible by removing initial inline styles from the DOM. + * Also, removes the button-placeholder container from the smart button block. * * Only relevant on the checkout page, i.e., when `this.isSeparateGateway` is `true` */ showPaymentGateway() { + if ( this.#gatewayInitialized ) { + return; + } + this.#gatewayInitialized = true; + if ( ! this.isSeparateGateway || ! this.isEligible ) { return; } - const styleSelectors = `style[data-hide-gateway="${ this.methodId }"]`; + const styleSelector = `style[data-hide-gateway="${ this.methodId }"]`; + const wrapperSelector = `#${ this.wrappers.Default }`; - const styles = document.querySelectorAll( styleSelectors ); + document + .querySelectorAll( styleSelector ) + .forEach( ( el ) => el.remove() ); + + document + .querySelectorAll( wrapperSelector ) + .forEach( ( el ) => el.remove() ); - if ( ! styles.length ) { - return; - } this.log( 'Show gateway' ); - styles.forEach( ( el ) => el.remove() ); - // This code runs only once, during button initialization, and fixes the initial visibility. this.isVisible = this.isCurrentGateway; }