Skip to content

fix(modal-checkout): suppress WooPayments express checkout when Stripe is active#2304

Open
wil-gerken wants to merge 6 commits intotrunkfrom
fix/modal-checkout-double-express-checkout
Open

fix(modal-checkout): suppress WooPayments express checkout when Stripe is active#2304
wil-gerken wants to merge 6 commits intotrunkfrom
fix/modal-checkout-double-express-checkout

Conversation

@wil-gerken
Copy link
Copy Markdown
Contributor

All Submissions:

  • Have you followed the Newspack Contributing guideline?
  • Does your code follow the WordPress' coding standards and VIP Go coding standards?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Changes proposed in this Pull Request:

When both Stripe and WooPayments are active with express checkout enabled, the modal checkout
renders two sets of Apple Pay / Google Pay buttons — one from each gateway.

The fix extends the existing filter_woocommerce_payments_settings() filter (which already
suppresses WooPay in the modal) to also remove payment_request from WooPayments'
express_checkout_checkout_methods when Stripe is active, and its express checkout is enabled.

Closes NPPM-2652.

How to test the changes in this Pull Request:

Before applying this PR:

  1. Activate both woocommerce-gateway-stripe and woocommerce-payments with express checkout
    enabled on each.
  2. Open the modal checkout via the Donate block.
  3. You will see two sets of Apple Pay / Google Pay buttons
download-1

Apply this PR:

  1. Reload the page, and confirm that only one set of Apple Pay / Google Pay buttons appears (Stripe's), with a single
    "Or" divider and the card form below.
download

Regression Check:

  1. Disable and Deactivate Stripe, leaving only WooPayments active. Reload the page and open the modal again to confirm
    WooPayments' express checkout buttons appear normally. This fix should only suppress when
    both gateways are active.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copilot AI review requested due to automatic review settings March 3, 2026 00:28
@wil-gerken wil-gerken requested a review from a team as a code owner March 3, 2026 00:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the modal checkout’s WooPayments settings filter to avoid rendering duplicate express checkout (Apple Pay / Google Pay) buttons when both Stripe and WooPayments are active.

Changes:

  • Disables WooPay (platform/hosted checkout) within modal checkout (existing behavior, now explicitly documented).
  • When Stripe express checkout is enabled, removes WooPayments’ payment_request method from express_checkout_checkout_methods to prevent duplicated express buttons in the modal.
Comments suppressed due to low confidence (1)

includes/class-modal-checkout.php:483

  • The inline comment references class-woocommerce-gateway-stripe.php, but that file doesn’t exist anywhere in this repository. Could you update the reference to the actual internal class/file in this codebase (or link to the upstream WooCommerce Stripe gateway source) so future readers can follow it?
		// Stripe is preferred: Newspack already manages its express checkout behavior (see
		// class-woocommerce-gateway-stripe.php), and WooPayments is already partially filtered
		// above (platform_checkout). WooPayments is suppressed, not the reverse.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wil-gerken wil-gerken requested review from Copilot and removed request for a team March 3, 2026 00:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

includes/class-modal-checkout.php:486

  • Relying on class_exists( 'WC_Stripe' ) here can fail depending on active plugin load order: if WooPayments reads its settings before the Stripe plugin has loaded its classes, class_exists() will be false and the duplicate express buttons won’t be suppressed. Consider detecting Stripe by checking whether the Stripe plugin is active (and ideally whether the gateway is enabled in woocommerce_stripe_settings['enabled']) rather than checking for a loaded class.
		if ( class_exists( 'WC_Stripe' ) ) {
			$stripe_settings = get_option( 'woocommerce_stripe_settings', [] );
			if ( isset( $stripe_settings['express_checkout'] ) && 'yes' === $stripe_settings['express_checkout'] ) {

includes/class-modal-checkout.php:483

  • This comment references newspack-plugin/includes/plugins/class-woocommerce-gateway-stripe.php, but that path/file doesn’t exist in this repository, so it’s not actionable for future maintainers. Please update the reference to a relevant location in this repo (or remove the parenthetical) to avoid confusion.
		// Stripe is preferred: Newspack already manages its express checkout behavior (see
		// newspack-plugin/includes/plugins/class-woocommerce-gateway-stripe.php), and WooPayments
		// is already partially filtered above (platform_checkout). WooPayments is suppressed, not the reverse.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

includes/class-modal-checkout.php:483

  • The inline comment references newspack-plugin/includes/plugins/class-woocommerce-gateway-stripe.php, but that path doesn’t exist in this repository, making it hard for reviewers to follow the trail. Consider replacing it with a stable reference (e.g., a GitHub URL) or rewording to describe the relevant integration without pointing at a non-local path.
		// Stripe is preferred: Newspack already manages its express checkout behavior (see
		// newspack-plugin/includes/plugins/class-woocommerce-gateway-stripe.php), and WooPayments
		// is already partially filtered above (platform_checkout). WooPayments is suppressed, not the reverse.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wil-gerken wil-gerken requested a review from a team March 3, 2026 16:47
Copy link
Copy Markdown
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this isn't working for me but I'm not sure if it's because of my specific testing site environment. When I log the output of get_option( 'woocommerce_stripe_settings', [] ); I see 'enabled' => 'yes' and 'express_checkout' => 'yes' but I don't see an express_checkout_checkout_methods key on the settings array. Subsequently, I still see the double express checkout buttons displayed in modal checkout.

It's possible the settings schema has changed in recent versions of the woocommerce-gateway-stripe plugin. I'm running v10.5.2—what version do you have?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wil-gerken wil-gerken force-pushed the fix/modal-checkout-double-express-checkout branch from d548ef5 to 873a75d Compare April 10, 2026 23:12
@wil-gerken
Copy link
Copy Markdown
Contributor Author

Hmm, this isn't working for me but I'm not sure if it's because of my specific testing site environment. When I log the output of get_option( 'woocommerce_stripe_settings', [] ); I see 'enabled' => 'yes' and 'express_checkout' => 'yes' but I don't see an express_checkout_checkout_methods key on the settings array. Subsequently, I still see the double express checkout buttons displayed in modal checkout.

It's possible the settings schema has changed in recent versions of the woocommerce-gateway-stripe plugin. I'm running v10.5.2—what version do you have?

@dkoo,

Sorry for the slow reply on this, and thanks for catching it!

The issue was that express_checkout_checkout_methods may not be present in the database, as your testing uncovered.

The original isset() guard caused the suppression to silently no-op in that case. WooPayments then fell back to its hardcoded default, which includes payment_request, so the duplicate buttons still appeared.

This revised fix initializes from the WooPayments default when the key is absent, so the suppression now applies regardless of the database state. I was able to reproduce your exact scenario locally by removing the key, and confirmed that the fix works in both cases: when the key is present and when it is absent.

Could you please take another look when you get a chance?

@wil-gerken wil-gerken requested a review from dkoo April 10, 2026 23:29
Copy link
Copy Markdown
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strangely, it's still not working for me! I verified that the settings are filtered by the filter_woocommerce_payments_settings callback with the expected values, too.

If I change the filtered value to the inline suggestion, it does successfully remove the WooPay express checkout buttons. However, I'm not sure if this might have any unintended side effects since it's a much farther-reaching settings change.

Comment on lines +546 to +549
// Always write the key — if it's absent from the DB, WooPayments falls back to its
// hardcoded default (['payment_request', 'woopay', 'amazon_pay']), bypassing this filter.
$methods = (array) ( $settings['express_checkout_checkout_methods'] ?? [ 'payment_request', 'woopay', 'amazon_pay' ] );
$settings['express_checkout_checkout_methods'] = array_values( array_diff( $methods, [ 'payment_request' ] ) );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Always write the key — if it's absent from the DB, WooPayments falls back to its
// hardcoded default (['payment_request', 'woopay', 'amazon_pay']), bypassing this filter.
$methods = (array) ( $settings['express_checkout_checkout_methods'] ?? [ 'payment_request', 'woopay', 'amazon_pay' ] );
$settings['express_checkout_checkout_methods'] = array_values( array_diff( $methods, [ 'payment_request' ] ) );
$settings['payment_request'] = 'no';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants