woocommerce / storefront

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

Enqueue wc-cart-fragments always, remove limit #2116

Closed albarin closed 1 year ago

albarin commented 1 year ago

As stated in https://github.com/woocommerce/storefront/pull/2113

From WooCommerce Core 7.8, the wc-cart-fragments isn't enqueued by default anymore. This causes https://github.com/woocommerce/storefront/issues/2101. I followed the "Best practices for the use of the “cart fragments” API" post to fix the issue.

This PR removes the limit_cart_sync_to_wc_pages, since the cart is present on Storefront on every page we need to always load wc-cart-fragments and not limit it to only WC pages.

Fixes https://github.com/woocommerce/storefront/issues/2101 & https://github.com/woocommerce/storefront/issues/2114

How to test the changes in this Pull Request:

  1. Go to a non-WooCommerce page, hover over the cart icon on the header, and confirm it displays the pop-up with the cart info.
  2. Add some products to the cart and go to the cart page, update the quantity of some of them, and make sure it's updated on the cart widget.
  3. Enable a caching plugin (like WP Super Cache) and visit a non-WooCommerce page.
  4. Go to the Shop and add some more products to the cart. Go back to the cached non-WooCommerce page from the last step and check the cart has the correct products and amount.

Changelog

Fix: Enqueue wc-cart-fragments script on all pages.