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

Disable WooCommerce Scripts and Styles on Non-Shop and Blog Pages

Conditionally remove WooCommerce frontend assets from pages that do not use products, checkout, cart, or account features.

Updated Aug 10, 2026 #woocommerce #performance #assets #css #php #snippet

WooCommerce can load its JavaScript and CSS on every WordPress page even when the page has no store functionality. Removing those assets from blog posts and marketing pages reduces requests and avoids parsing code that the visitor never uses.

Add this snippet to a child theme’s functions.php file or a code snippets plugin. Keep the shop, product, cart, checkout, and account pages intact.

The snippet

functions.php
add_action( 'wp_enqueue_scripts', function() {
if ( is_admin() ) {
return;
}
$commerce_page = is_woocommerce() || is_cart() || is_checkout() || is_account();
if ( $commerce_page ) {
return;
}
// Core WooCommerce styles and scripts.
wp_dequeue_style( 'woocommerce-general' );
wp_dequeue_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'js-cookie' );
wp_dequeue_script( 'woocommerce-general' );
}, 100 );

Why this should be conditional

is_woocommerce() covers WooCommerce-managed shop, product, category, and tag views, but it does not cover cart, checkout, or account pages. The additional checks protect those endpoints explicitly. If your theme places a product block, cart widget, or wishlist shortcode on a regular page, add that page to the allowlist before using the snippet.

Asset handles vary between WooCommerce versions, themes, and extensions. View the page source or use the browser Network panel to identify any remaining wc- assets. Do not remove an extension’s script just because it contains woocommerce in its filename; it may be required by a shortcode on that page.

This technique complements, rather than replaces, page caching and asset optimization. Test the header, footer, navigation, product embeds, and any AJAX widgets after enabling it.

Start with disabling cart fragments on non-commerce pages if the store only needs a live cart on shop and checkout screens. The official WordPress references for wp_dequeue_script() and wp_dequeue_style() cover the functions used here.