fix: Respect express checkout location settings on block-based cart#11382
Open
fix: Respect express checkout location settings on block-based cart#11382
Conversation
The canMakePayment callback in the blocks express payment registration did not check the enabled_methods array, allowing Apple Pay / Google Pay to appear on the cart page even when the cart location was unchecked. Additionally, isPaymentRequestEnabled in payment_fields_js_config hardcoded the 'checkout' location, so it was always true on any page as long as checkout had express checkout enabled. Fix both: add enabled_methods guard to canMakePayment for all three express payment methods, and make payment_fields_js_config context- dependent with a fallback for empty contexts (admin/AJAX). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add JS tests for canMakePayment enabled_methods checking in blocks registration (10 tests), and PHP tests for context-dependent payment_fields_js_config (4 tests). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document the dual data path for express checkout in WooCommerce blocks and the location-centric settings model introduced in 10.4.0. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
Contributor
|
Size Change: +53 B (0%) Total Size: 956 kB
ℹ️ View Unchanged
|
…mazon Pay Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
frosso
approved these changes
Feb 20, 2026
Contributor
frosso
left a comment
There was a problem hiding this comment.
Checked since Dat is AFK, seems to be working well 👍 just one question about the fallback mechanism introduced
|
|
||
| $config['isPaymentRequestEnabled'] = $this->gateway->is_payment_request_enabled() | ||
| && ( | ||
| empty( $context ) |
Contributor
There was a problem hiding this comment.
Why is the empty( $context ) fallback needed here? What scenario would break without this fallback?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes WOOPMNT-5763
Changes proposed in this Pull Request
When only "Show on checkout page" is selected in the Apple Pay / Google Pay display settings, the Cart block still shows express checkout buttons. This happens because:
isPaymentRequestEnabledinpayment_fields_js_confighardcoded the'checkout'location, so it was alwaystrueon the cart page as long as checkout had express checkout enabled — causingregisterExpressPaymentMethod()to be called.canMakePaymentcallbacks for block express payment methods only checked if Stripe supports the payment method on the device, never checkingenabled_methodsfor the current page context.Regression introduced in: PR #11267, shipped in 10.5.0. That PR broadened
should_show_express_checkout_button()from checking onlypayment_requestper-location tois_any_express_checkout_method_enabled_at(), which returnstrueif any express method (including Amazon Pay) is enabled at that location. This causedwcpayExpressCheckoutParamsto be localized even when Apple Pay/Google Pay were disabled for that location. It also addedpayment_fields_js_configwith'checkout'hardcoded, and neither thecanMakePaymentcallbacks nor the new method were updated with per-method location filtering.Fix:
enabled_methodsguard tocanMakePaymentfor Apple Pay, Google Pay, and Amazon Pay in the blocks registration. If the method isn't enabled for the current page context, returnfalseimmediately.payment_fields_js_configcontext-dependent: useget_button_context()instead of hardcoding'checkout', with a fallback for empty contexts (admin/AJAX) to maintain current behavior.Testing instructions
npm run changelogto add a changelog filePost merge
🤖 Generated with Claude Code