Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

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.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Needs WooCommerce
  • Category WooCommerce
  • Tested with WordPress 7.1, WooCommerce 11.1

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
<?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

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.