Load WooCommerce scripts and styles only on shop pages
WooCommerce’s CSS and JavaScript load only on the shop, product, cart, checkout and account pages, not on your blog posts and other pages.
Before you switch it on: Switch it on, then open a blog post: if your header’s mini cart or a product block stops working there, switch it off again.
It arrives switched off, even when you install its whole pack with "Switch on after installing".
<?php
add_action(
'wp_enqueue_scripts',
static function () {
if ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) {
return;
}
foreach ( array( 'woocommerce-general', 'woocommerce-layout', 'woocommerce-smallscreen', 'woocommerce-blocktheme', 'wc-blocks-style' ) as $style ) {
wp_dequeue_style( $style );
}
foreach ( array( 'wc-cart-fragments', 'woocommerce', 'wc-add-to-cart', 'sourcebuster-js', 'wc-order-attribution' ) as $script ) {
wp_dequeue_script( $script );
}
},
99
);
Good to know
A mini cart in the header or product blocks on other pages may need these files: check those pages after switching it on. Removing order attribution scripts means WooCommerce can’t record where orders came from on visits that start on those pages.
In these packs
- More speed: More ways to load less: block styles, speculative loading, fewer scripts.
- WooCommerce: account, emails and admin: A leaner My account page, handier order lists and emails, and lighter pages.