Prevent early is_enabled()
check for Google Pay button in new UI (5021)
#3566
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.
Issue Description
The Problem
In the old UI, we don’t have location-based settings for the Google Pay button. Instead, we rely on a single setting —
googlepay_button_enabled
— to enable or disable the button globally across all locations.In the new UI, however, we support location-based settings, and we map the
googlepay_button_enabled
option individually for each location.The issue arises because, during block registration, we call
$button->is_enabled()
. This method uses ContextTrait to determine the current context. But inside thewoocommerce_blocks_payment_method_type_registration
hook, context-detection functions likeis_cart()
always returnfalse
, because this hook is triggered too early in the WordPress lifecycle, before those context functions are properly initialized.As a result, the context defaults to
'mini-cart'
, which is typically disabled by default. This leads to$button->is_enabled()
returningfalse
, and the Google Pay payment method is not registered in the block cart.PR Description
This PR prevents early
is_enabled()
check for Google Pay button in new UI.In the new UI, the Google Pay button availability is determined by gateway enablement and location selection, not a global setting. The
is_enabled()
check depends on context functions (likeis_cart()
), which returnfalse
too early during block registration.