← Back to All Snippets

Disable WooCommerce Cart Fragments AJAX Script on Non-Shop Pages

⚡ Target: functions.php 🔒 Tested: WP 6.6+ / PHP 8.2+ 💻 Lang: PHP
PHP (functions.php)
add_action( 'wp_enqueue_scripts', 'tipwp_disable_cart_fragments_selectively', 99 );
function tipwp_disable_cart_fragments_selectively() {
    if ( function_exists( 'is_woocommerce' ) ) {
        if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
            wp_dequeue_script( 'wc-cart-fragments' );
        }
    }
}

WooCommerce loads wc-cart-fragments.js on every page to update mini-carts via AJAX. This snippet disables it on blog and content pages to save 300ms TTFB.

← Back to All Snippets Explore Dev Tools →