-
Notifications
You must be signed in to change notification settings - Fork 219
Add to cart button ignored redirect to cart setting #5708
Add to cart button ignored redirect to cart setting #5708
Conversation
For the time being we expose only what is used by the blocks which is `cartRedirectAfterAdd`. In the future more can be added as needed. Setting is accessible via `getSetting( 'productsSettings' )`. We namespace the settings under productsSettigns to reflect the domain and how settings are organised in Woo admin and to inform that this is an object with more settings within. This setting normally was available **only** if AJAX add to cart was set as a js global `wc_add_to_cart_params.cart_redirect_after_add`. By accessing the option directly we ensure it’s exposed to blocks regardless of if AJAX option is enabled.
This adds the redirect directly on the AddToCartButton after succesful add to cart action. This follows convention that redirects or other side effects shouldn’t happen as part of the action but rather be part of the control that triggers such flow.
I've explored hooking it up in (And thanks @opr for the support and pointers!) |
Size Change: +178 B (0%) Total Size: 811 kB
ℹ️ 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.
Great job. I love the well-thought-through PR description with all your thoughts and all that was done, and the comments in the code.
I'm just wondering… are we (or Gutenberg) not using any form of router? Redirecting via hard-coding the window.location.href
feels a bit crude.
But if we don't have any routing set up, then no problem!
Was curious about it as well when working on this @sunyatasattva. Woo is not a SPA and out of the box it doesn't have any routers or custom history handler contexts it seems. WooCommerce extension where it does redirect does it this way as well. |
This fixes issue where All Products (and all other blocks) where Add to Cart button was present were ignoring the Redirect to Cart after item added setting was enabled.
We expose WooCommerce products settings in
wcSettings
For the time being we expose only what is used by the blocks
which is
cartRedirectAfterAdd
. In the future more can be addedas needed. Setting is accessible via
getSetting( 'productsSettings' )
.We namespace the settings under productsSettigns to reflect
the domain and how settings are organised in Woo admin and to
inform that this is an object with more settings within.
This setting normally was available only if AJAX add to cart was set
as a JS global
wc_add_to_cart_params.cart_redirect_after_add
.By accessing the option directly we ensure it’s exposed
to blocks regardless of if AJAX option is enabled.
This adds the redirect directly on the AddToCartButton after successful
add to cart action and it follows convention that redirects or other side
effects shouldn’t happen as part of the action but rather be part of the
control that triggers such flow.
Fixes #1766
Manual Testing
How to test the changes in this Pull Request:
User Facing Testing
These are steps for user testing (where "user" is someone interacting with this change that is not editing any code).
Changelog