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

Join 1,653,898+ Happy Site Owners Using Astra

Whether you are a beginner, small business owner, or professional web developer, Astra provides all the tools you need to easily build your beautiful WordPress website.

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