From a453e4e88102742c0cbb42f71c3ac044757f77f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=BCsken?= Date: Thu, 17 Oct 2024 14:18:19 +0200 Subject: [PATCH] Display payment gateways also when the are set to display:none with css and the stylesheet is removed from DOM --- modules/ppcp-applepay/resources/js/ApplepayButton.js | 5 +++++ .../js/modules/Renderer/CardFieldsFreeTrialRenderer.js | 6 ++++++ .../resources/js/modules/Renderer/CardFieldsRenderer.js | 6 ++++++ .../resources/js/modules/Renderer/HostedFieldsRenderer.js | 6 ++++++ .../resources/js/modules/Renderer/PaymentButton.js | 5 +++++ 5 files changed, 28 insertions(+) diff --git a/modules/ppcp-applepay/resources/js/ApplepayButton.js b/modules/ppcp-applepay/resources/js/ApplepayButton.js index 0f217f606..8b187318a 100644 --- a/modules/ppcp-applepay/resources/js/ApplepayButton.js +++ b/modules/ppcp-applepay/resources/js/ApplepayButton.js @@ -407,6 +407,11 @@ class ApplePayButton { .querySelectorAll( 'style#ppcp-hide-apple-pay' ) .forEach( ( el ) => el.remove() ); + const paymentMethodAppleLi = document.querySelector('.wc_payment_method.payment_method_ppcp-applepay' ); + if (paymentMethodAppleLi.style.display === 'none' || paymentMethodAppleLi.style.display === '') { + paymentMethodAppleLi.style.display = 'block'; + } + this.allElements.forEach( ( element ) => { element.style.display = ''; } ); diff --git a/modules/ppcp-button/resources/js/modules/Renderer/CardFieldsFreeTrialRenderer.js b/modules/ppcp-button/resources/js/modules/Renderer/CardFieldsFreeTrialRenderer.js index b97569762..93e6ddf3e 100644 --- a/modules/ppcp-button/resources/js/modules/Renderer/CardFieldsFreeTrialRenderer.js +++ b/modules/ppcp-button/resources/js/modules/Renderer/CardFieldsFreeTrialRenderer.js @@ -38,6 +38,12 @@ class CardFieldsFreeTrialRenderer { if ( hideDccGateway ) { hideDccGateway.parentNode.removeChild( hideDccGateway ); } + const dccGatewayLi = document.querySelector( + '.wc_payment_method.payment_method_ppcp-credit-card-gateway' + ); + if (dccGatewayLi.style.display === 'none' || dccGatewayLi.style.display === '') { + dccGatewayLi.style.display = 'block'; + } this.errorHandler.clear(); diff --git a/modules/ppcp-button/resources/js/modules/Renderer/CardFieldsRenderer.js b/modules/ppcp-button/resources/js/modules/Renderer/CardFieldsRenderer.js index 4a0ec09f2..96196d0cd 100644 --- a/modules/ppcp-button/resources/js/modules/Renderer/CardFieldsRenderer.js +++ b/modules/ppcp-button/resources/js/modules/Renderer/CardFieldsRenderer.js @@ -44,6 +44,12 @@ class CardFieldsRenderer { if ( hideDccGateway ) { hideDccGateway.parentNode.removeChild( hideDccGateway ); } + const dccGatewayLi = document.querySelector( + '.wc_payment_method.payment_method_ppcp-credit-card-gateway' + ); + if (dccGatewayLi.style.display === 'none' || dccGatewayLi.style.display === '') { + dccGatewayLi.style.display = 'block'; + } const cardFields = paypal.CardFields( { createOrder: contextConfig.createOrder, diff --git a/modules/ppcp-button/resources/js/modules/Renderer/HostedFieldsRenderer.js b/modules/ppcp-button/resources/js/modules/Renderer/HostedFieldsRenderer.js index f49d9e9ed..5160c5cde 100644 --- a/modules/ppcp-button/resources/js/modules/Renderer/HostedFieldsRenderer.js +++ b/modules/ppcp-button/resources/js/modules/Renderer/HostedFieldsRenderer.js @@ -52,6 +52,12 @@ class HostedFieldsRenderer { if ( hideDccGateway ) { hideDccGateway.parentNode.removeChild( hideDccGateway ); } + const dccGatewayLi = document.querySelector( + '.wc_payment_method.payment_method_ppcp-credit-card-gateway' + ); + if (dccGatewayLi.style.display === 'none' || dccGatewayLi.style.display === '') { + dccGatewayLi.style.display = 'block'; + } const cardNumberField = document.querySelector( '#ppcp-credit-card-gateway-card-number' diff --git a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js index 3ce35c9b5..e3df4c969 100644 --- a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js +++ b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js @@ -763,11 +763,16 @@ export default class PaymentButton { const styleSelector = `style[data-hide-gateway="${ this.methodId }"]`; const wrapperSelector = `#${ this.wrappers.Default }`; + const paymentMethodLi = document.querySelector(`.wc_payment_method.payment_method_${ this.methodId }`); document .querySelectorAll( styleSelector ) .forEach( ( el ) => el.remove() ); + if (paymentMethodLi.style.display === 'none' || paymentMethodLi.style.display === '') { + paymentMethodLi.style.display = 'block'; + } + document .querySelectorAll( wrapperSelector ) .forEach( ( el ) => el.remove() );