From 07e4388538d2feee6ad938f0e8e8b67e07de1d2a Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Tue, 1 Dec 2026 11:49:48 -0400 Subject: [PATCH] Fix PayPal subscription buttons with a saved card-only layout --- paypal/js/frontend.js | 2 +- tests/js/paypalBootstrap.test.mjs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/paypal/js/frontend.js b/paypal/js/frontend.js index 423d010539..b4c16d1e91 100644 --- a/paypal/js/frontend.js +++ b/paypal/js/frontend.js @@ -147,7 +147,7 @@ isRecurring = 'single' !== settings.one; const { paypalLayout: layout } = settings; const cardFieldsAreSupported = layout !== 'checkout_only' && 'function' === typeof window.paypal.CardFields; - const buttonsAreEnabled = layout !== 'card_only' && 'function' === typeof window.paypal.Buttons; + const buttonsAreEnabled = ( isRecurring || layout !== 'card_only' ) && 'function' === typeof window.paypal.Buttons; const runId = ++initRunId; diff --git a/tests/js/paypalBootstrap.test.mjs b/tests/js/paypalBootstrap.test.mjs index 3756778ec9..639549f643 100644 --- a/tests/js/paypalBootstrap.test.mjs +++ b/tests/js/paypalBootstrap.test.mjs @@ -92,12 +92,16 @@ async function checkOverlappingInitialization() { querySelector: () => element, createElement: () => ( { classList: { add() {} }, append() {} } ), }, - getPayPalSettings: () => [ { one: 'single', paypalLayout: 'checkout_only' } ], + getPayPalSettings: () => [ { one: 'recurring', paypalLayout: 'card_only' } ], waitForVisiblePaymentField: async () => {}, listenForFieldMutations() {}, listenForSubmitButtonMutations() {}, paymentMethods: methods, - discoverPaymentMethods: async () => methods.set( 'paypal', { eligible: true, render: async () => {} } ), + discoverPaymentMethods: async ( { buttonsAreEnabled } ) => { + if ( buttonsAreEnabled ) { + methods.set( 'paypal', { eligible: true, render: async () => {} } ); + } + }, discoverDeferredPaymentMethods: () => { waiting++; return gate; }, @@ -123,7 +127,7 @@ async function checkOverlappingInitialization() { assert.equal( selectorCount, 1, 'Only the latest run should render the payment selector.' ); } -test( 'PayPal renders only the latest initialization after asynchronous discovery', checkOverlappingInitialization ); +test( 'PayPal renders only the latest subscription buttons with a saved Card only layout', checkOverlappingInitialization ); test( 'superseded wallet discovery does not register methods in the current run', async () => { const start = source.indexOf( '\tasync function discoverDeferredPaymentMethods(' );