Disable WooCommerce Cart Fragments Outside the Shop
Stops the cart fragments script, which fires an extra uncached AJAX request on every page, everywhere except the shop, product, cart and checkout pages.
Opens WPIDE on
Code
add_action( 'wp_enqueue_scripts', function () {
if ( ! function_exists( 'is_woocommerce' ) ) {
return;
}
if ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) {
return;
}
wp_dequeue_script( 'wc-cart-fragments' );
}, 999 );
Notes
A mini-cart in the header will not update live on other pages until the visitor reaches a shop page.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.