Skip to content

Instantly share code, notes, and snippets.

Last active March 22, 2021 11:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Remove WooCommerce scripts and styles.
* Remove WooCommerce scripts and styles.
* Cart fragments are used for things like ajax cart menu icons,
* but it's really slow, so let's only keep them where necessary.
* @version 1.3.0
* @author Mike Hemberger @JiveDig
* @link
* @return void
add_action( 'wp_enqueue_scripts', function() {
// Bail if WooCommerce is not active.
if ( ! class_exists( 'WooCommerce' ) ) {
// Bail if on WooCommerce pages.
if ( is_shop() || is_product() || is_cart() || is_checkout() || is_account_page() ) {
// Remove the generator tag.
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
$scripts = [
// 'prettyPhoto',
// 'prettyPhoto-init',
// 'jquery-blockui',
// 'jquery-placeholder',
// 'jquery-payment',
// 'fancybox',
// 'jqueryui',
$styles = [
'printful-global', // printful-shipping-for-woocommerce
'wcsatt-css', // woocommerce-all-products-for-subscriptins
'wc-gateway-ppec-frontend', // woocommerce-gateway-paypal-express-checkout
'wc-memberships-frontend', // woocommerce-memberships
// 'select2',
foreach ( $scripts as $handle ) {
wp_dequeue_script( $handle );
foreach ( $styles as $handle ) {
wp_dequeue_style( $handle );
}, 999 );
Copy link

Elwood-P commented Mar 19, 2021

Tx very useful. You missed a few scripts:
'zoom', 'flexslider', 'photoswipe-ui-default', 'photoswipe',

and one style:

Copy link

JiveDig commented Mar 20, 2021

Interesting, in my testing with Query Monitor I didn’t see those loading on other pages. Are you seeing them loaded on your site(s)? Maybe it’s related to some features or add-ons I haven’t used?

Copy link

I should have been clearer, I am removing WC scripts & styles from all pages including WC pages (so much junk!), so these assets were being loaded on a product page. They get loaded by default on themes that havn't declared support for WC using add_theme_support('woocommerce');.

Thanks for the reference to Query Monitor by the way. I have no idea why I havn't come across this before, it looks so useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment