How To Disable WooCommerce Cart Fragments

WooCommerce sites especially larger ones or ones who are hosted on a slow host tend to have one small yet slow request. The request is an ajax request that WooCommerce makes by default on all fresh installs of woocommerce.

Even on a relatively small site who is on a slower host this request can take anywhere from 2-3 seconds or in really slow cases it can take 10+ seconds. The request is what handles your WooCommerce cart typically in your header. For instance, if your cart in the header on hover shows the contents of the cart this is the script that makes that possible. If you need to retain that functionality you’re much better off looking for a better host.

I recommend some of the following who have been excellent from my experience.

  • SiteGround (relatively inexpensive comes with email hosting). I used SiteGround previously on the GrowBig plan. You want at the minimum the GrowBig plan. That way you can access their Memcached caching for database queries this helps a lot on WooCommerce sites.
  • Cloudways this website is actually hosted on Cloudways right now and it has been great. However, it doesn’t offer email hosting but I use GSuite anyway for more reliable and secure email deliverability anyway. I also saved $120 a year compared to my previous GrowBig plan on SiteGround.
  • Kinsta is by far my favorite host but its expensive. You will get better performance on Kinsta than on Cloudways or SiteGround but it’s very expensive. I have several sites hosted on my Cloudways instance (around 10 or so) which would cost me $200 a month instead of the $10 a month I currently pay. But if you only have a single website Kinsta provides you with performance that is superior to that of the competition. But for my case, it was just too expensive without enough benefit for the traffic these sites generate!

How To Disable WooCommerce Cart Fragments

Step 1. Go into your WooCommerce Settings go to products and turn off enable ajax add to cart buttons on archives. Also go ahead and redirect them to the cart page on addition. This step is technically optional but it’s done to force users to redirect to the cart page to avoid issues with caching setups.

Step 2. Dequeue the cart fragments JS. You can do this in a couple of ways for instance you can simply copy the below snippet into your child theme functions.php file or into a plugin like Code Snippets.

/** Disable Ajax Call from WooCommerce */
function sert_dequeue_woocommerce_cart_fragments() { 

add_action( 'wp_enqueue_scripts', 'sert_dequeue_woocommerce_cart_fragments', PHP_INT_MAX); 

The above snippet simply dequeues that JavaScript file altogether or if you aren’t comfortable with code I prepared it as a plugin you can just download and install.

Alternatively, you could use a premium plugin like Perfmatters which also comes with additional functionality for cleaning up your website.

Closing Thoughts

Remember that removing the script can and will break features such as the ajax powered header cart you might have on your website. It can also break companion plugins such as any floating cart plugins you might have installed. If retaining functionality is important you should consider swapping to a better host.

scott hartley

About the author

Scott is a web performance geek, lover of all things coffee, and avid video game player. His WordPress work delves into web performance, web security, and SEO.

Leave a Comment