← Back to notes
snippet 1 min read PHP 7.4+ WP 5.8+

Disable WooCommerce Cart Fragments AJAX on Non-eCommerce Pages

Stop the cart fragments request on posts and other non-commerce pages for a lighter WooCommerce frontend and a potential 100–300ms speed improvement.

Updated Aug 13, 2026 #woocommerce #performance #javascript #php #snippet

WooCommerce cart fragments can make an AJAX request to keep a mini-cart synchronized. That is useful on shop and cart pages, but it is often unnecessary on blog posts, landing pages, and documentation. Removing that request from non-commerce pages can reduce connection and execution time, especially on mobile or uncached pages.

Add this snippet to a child theme’s functions.php file or a code snippets plugin.

The snippet

functions.php
add_action( 'wp_enqueue_scripts', function() {
if ( is_admin() ) {
return;
}
// Keep fragments on pages where the cart or mini-cart is expected to update.
$commerce_pages = is_woocommerce() || is_cart() || is_checkout() || is_account();
if ( ! $commerce_pages ) {
wp_dequeue_script( 'wc-cart-fragments' );
wp_deregister_script( 'wc-cart-fragments' );
}
}, 100 );

Why the priority matters

Themes and plugins may enqueue the script after the default WooCommerce hook has run. Running at priority 100 gives those scripts time to be registered before the dequeue happens. If another plugin re-enqueues the script later, inspect its hook and move this callback later or remove the enqueue at its source.

Check your header and mini-cart

This is safe only when non-commerce pages do not need a live cart count. A header mini-cart shown on every page may stop updating until the next full page load. In that case, keep fragments on pages with the mini-cart, or replace the widget with a cached count that refreshes through your own endpoint.

Measure the result with the browser Network panel or a performance tool rather than assuming a fixed improvement. The 100–300ms range depends on hosting, cache headers, connection setup, and the number of scripts already on the page.

For a broader asset cleanup, continue with disabling WooCommerce scripts and styles on non-shop pages. WordPress’s script dequeue reference explains why this callback runs at a late priority.