Disable WooCommerce Cart Fragments

Disable WooCommerce “Cart Fragments” using plugins or code snippets. WooCommerce “Cart Fragments” (wc-ajax=get_refreshed_fragments) is a script using admin ajax to update the cart without refreshing the page. 

Disable WooCommerce Cart Fragments

Disable Cart Fragments

You can disable the WooCommerce Cart fragments using plugins or manually by editing the functions.php.

Disable Cart Fragments using the “Disable Cart Fragments” plugin

You can download and activate the plugin: Disable Cart Fragments
No further actions are needed, AJAX cart fragmentation should reduce automatically and will only be allowed where needed.

Disable Cart Fragments using Perfmatters

Perfmatters allows you to disable cart fragmentation with a click of a button and some more features to speed up WooCommerce websites. Read the guide on how to disable cart fragmentation: Disable WooCommerce cart fragments AJAX

delay cart-fragments.min.js wordpress woocommerce perfmatters

Disable Cart Fragments using Flying Scripts

I discovered that it is also possible to delay the cart fragmentation script “cart-fragments.min.js” until user interaction. Flying scripts is a plugin that helps you to delay non critical JavaScript until user interaction or a specific time.

Delay cart-fragments.min.js in flying scripts

Add WooCommerce Cart Fragments to Flying Scripts
cart-fragments.min.js

Disable Cart Fragments in functions.php

  1. Disable Cart Fragments on the front page
  2. Disable Cart Fragmentation on Front Page and Posts
  3. Disabling All WooCommerce Styles and Scripts Site Wide

Disable Cart Fragments on the front page

/** Disable Ajax Call from WooCommerce */
add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11); 
function dequeue_woocommerce_cart_fragments() { if (is_front_page()) wp_dequeue_script('wc-cart-fragments'); }

Disable Cart Fragmentation on Front Page and Posts

/** Disable Ajax Call from WooCommerce on front page and posts*/
add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11);
function dequeue_woocommerce_cart_fragments() {
if (is_front_page() || is_single() ) wp_dequeue_script('wc-cart-fragments');
}

Disabling All WooCommerce Styles and Scripts Site Wide

/** Disable All WooCommerce  Styles and Scripts Except Shop Pages*/
add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_styles_scripts', 99 );
function dequeue_woocommerce_styles_scripts() {
if ( function_exists( 'is_woocommerce' ) ) {
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
# Styles
wp_dequeue_style( 'woocommerce-general' );
wp_dequeue_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_style( 'woocommerce_fancybox_styles' );
wp_dequeue_style( 'woocommerce_chosen_styles' );
wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
# Scripts
wp_dequeue_script( 'wc_price_slider' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-add-to-cart-variation' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-chosen' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'prettyPhoto' );
wp_dequeue_script( 'prettyPhoto-init' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
wp_dequeue_script( 'fancybox' );
wp_dequeue_script( 'jqueryui' );
}
}
}

Warning: add only one of the code snippets from the above three options. Don’t add multiple or all codes in your functions.php file. When you disable the scripts side wide, also disable “Enable Ajax add to cart buttons on archives” option available under the “Display” section of “WooCommerce > Settings” menu.

Relevant Articles: