woocommerce / storefront

Official theme for WooCommerce
https://wordpress.org/themes/storefront/
972 stars 471 forks source link

Load wc-cart-fragments-script when the widget cart is active #2115

Closed gigitux closed 1 year ago

gigitux commented 1 year ago

Fixes #2114

With #2113, we start to enqueue the wc-cart-fragments-script only on WooCommerce Pages, but the Mini Cart Widget can be loaded in all the pages of WordPress. So, I update the logic to ensure that the script is loaded when the Mini Cart Widget is active.

Screenshots

How to test the changes in this Pull Request:

  1. Install WP-Optimize - Clean, Compress, Cache plugin.
  2. Enable the cache.
  3. Add the Mini Cart widget via the widget page (Appareance > Widget). Add in the header.
  4. Create a post and add the On Sale Products block (it is important that it is an old block that it is server side). Save it.
  5. Visit the post.
  6. Add the products in the cart.
  7. Ensure that the Mini Cart widget is updated.
  8. Refresh the page.
  9. Ensure that the Mini Cart widget is loaded and shows the right product in the cart.

-

Changelog

Load wc-cart-fragments-script when Mini Cart widget is active.

A-Printer commented 1 year ago

This PR fixes things with the cart widget, but not with the cart that is present in the menu, here on the right of the screen.

gigitux commented 1 year ago

This PR fixes things with the cart widget, but not with the cart that is present in the menu, here on the right of the screen.

Thanks for the feedback! Could you share some reproduction steps, please?

This is an attempt that I did and it seems that works correctly:

webwit commented 1 year ago

Try it on the homepage or other none woo page (and without mini cart) ?

A-Printer commented 1 year ago

Here you can see that the cart is updating on the WooCommerce pages, but not on the Contact page:

https://github.com/woocommerce/storefront/assets/87852864/c330dbe1-05be-4896-89d3-82dc37140dfd

webwit commented 1 year ago

Yeah this doesn't fix the cart at the top right as I also reported in #2114. I don't use the mini cart. The top right cart is part of the storefront templates, that header is used all over my site. Ehm, just a layman, but that function to only include it on some pages based on conditions - if you're running storefront with that cart always in the header, what is the purpose?

A-Printer commented 1 year ago

@gigitux I agree with @webwit, since by default the cart (not the widget) is part of the navigation and is present on every page, it should get refreshed with wc-cart-fragments-script on every page, no exceptions.

albarin commented 1 year ago

Hi @webwit and @A-Printer, thanks for your suggestions! 🙌
Could you have a look at this new PR https://github.com/woocommerce/storefront/pull/2116 and see if it fixes the issue for you? Thanks a lot!

webwit commented 1 year ago

Hi Alba,

I'm out and didn't test, but that should do it as yesterday I outcommented the call to add_filter to limit_cart_sync_to_wc_pages and that fixed it for me. #2116 removes that and effectively does the same.

A-Printer commented 1 year ago

@albarin I can confirm that #2116 does fix the issue. Thanks!

albarin commented 1 year ago

Thank you both for your help! We'll create a new release as soon as possible.