No results found. Try again with different words?

Search must be at least 3 characters.

How to disable cart fragments on WooCommerce?

Sidebar Image

Did not find a solution? We are here to help you succeed.

Woocommerce cart fragments are the Ajax requests that are responsible for handling the cart option on the header. For example, when the users on your website add a product in the cart and later click on the cart option on the header, this request shows the items available on the cart. For instance, this script enables your cart to display its contents when the user hovers over it in the header.

Why do I need to disable this request?

These requests are enabled by default on fresh installation of the WooCommerce plugin and seems like a great feature to have. The only downside of this feature is that if you are on a slow hosting provider, it might take up to 3-5 minutes to load and thus reduces the overall loading speed of your entire website. We recommend you to disable this feature if you are on a slow hosting provider.

How to disable the cart fragments?

You can use the following steps to disable the cart fragments script on your WooCommerce website:

Step1: Navigate to the WooCommerce Settings and click on products

Step 2: uncheck the box that says “Enable Ajax add to cart button archive”

Accessing cart fragment

Step 3: Check the box that says “Redirect to the cart page after successful addition”

accessing product

These options are technically optional but this will ensure to bypass any cache plugin that you have installed on your website.

Step 4: in order to dequeue the JavaScript you may need to add the following snippet into the functions.php file of your child theme. If you are not sure what a Child Theme is, here is an article that will guide you through. Please navigate to the appearance and theme file editor and click on the child theme’s function.php file.

Ast-child-theme

Copy the snippet below and paste into the bottom of the function.php file. Don’t forget to save the file.

/** Disable Ajax Call from WooCommerce */
function sert_dequeue_woocommerce_cart_fragments() { 
	wp_dequeue_script('wc-cart-fragments'); 
}

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

The aforementioned code snippet just dequeues the entire JavaScript file and disables the WooCommerce cart fragments to ensure that your site runs faster even on the slow hosting providers.

Was this article helpful?
Sidebar Image

Did not find a solution? We are here to help you succeed.

Related Docs

Astra is Free. Now & Forever.

We believe creating beautiful websites should not be expensive. That's why Astra is free for everyone. Get started for free and extend with affordable packages.

REWIND

YEAR IN REVIEW

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form
Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form