-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ECE script dependencies with WC 9.7 #10461
Conversation
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. |
Size Change: 0 B Total Size: 1.29 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I wasn't able to replicate the issue using checkout, I was able to do it using blocks cart and verified that the fix is working as intended.
The only downside I see is that the wcpayExpressCheckoutParams
variable will be embedded twice in the page, but it shouldn't have a noticeable impact.
That's a good point - as a possible alternative, we could do this: if ( has_block( 'woocommerce/cart' ) || has_block( 'woocommerce/checkout' ) ) {
wp_localize_script( 'WCPAY_BLOCKS_CHECKOUT', 'wcpayExpressCheckoutParams', $express_checkout_params );
} else {
wp_localize_script( 'WCPAY_EXPRESS_CHECKOUT_ECE', 'wcpayExpressCheckoutParams', $express_checkout_params );
} But I'm not sure about the longer term maintenance 😬 |
I think that may work but I'm also unaware of other edge cases that may be present, it also looks like we already have the WC_Payments_Utils::is_cart_block function to check for cart blocks usage. I was going to suggest checking if |
Thank you for linking that! Yeah, I think there's a possibility for breaking things if we follow the conditional approach 😬 I think I'm going to leave it as-is for now, the |
Fixes #
Changes proposed in this Pull Request
In WC 9.7.0 there's been some optimizations implemented, which make the
canMakePayment
function being executed earlier in the page's lifecycle, compared to prior versions of WC.The ECE (both "tokenized" ECE and non-tokenized ECE) on blocks cart/checkout pages are dependent on the
wcpayExpressCheckoutParams
global variable, which is enqueued by the backend.The problem is that WC 9.7.0 will execute the
canMakePayment
function before thewcpayExpressCheckoutParams
is evaluated on the page.This results on the GooglePay/ApplePay buttons not being visible on the cart/checkout pages on first load, unless the customer interacts with the cart (or checkout): changing product quantities, adding a coupon, changing billing or shipping address, changing the selected shipping rate make the button re-appear.
Sometimes, even refreshing or re-visiting cart/checkout works.
This solution ensures that the
wcpayExpressCheckoutParams
is added to the page as a direct dependency of our blocks scripts, so that it can already be present when evaluated in thecanMakePayment
function.Testing instructions
npm run changelog
to add a changelog file, choosepatch
to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge