Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove WooCommerce styles and scripts.
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below into functions.php
/**
* Manage WooCommerce styles and scripts.
*/
function grd_woocommerce_script_cleaner() {
// Remove the generator tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
// Unless we're in the store, remove all the cruft!
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_style( 'woocommerce-general');
wp_dequeue_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
wp_dequeue_style( 'woocommerce_fancybox_styles' );
wp_dequeue_style( 'woocommerce_chosen_styles' );
wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
wp_dequeue_script( 'selectWoo' );
wp_deregister_script( 'selectWoo' );
wp_dequeue_script( 'wc-add-payment-method' );
wp_dequeue_script( 'wc-lost-password' );
wp_dequeue_script( 'wc_price_slider' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'wc-credit-card-form' );
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-add-to-cart-variation' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-chosen' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'prettyPhoto' );
wp_dequeue_script( 'prettyPhoto-init' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
wp_dequeue_script( 'jquery-payment' );
wp_dequeue_script( 'fancybox' );
wp_dequeue_script( 'jqueryui' );
}
}
add_action( 'wp_enqueue_scripts', 'grd_woocommerce_script_cleaner', 99 );
@yupii1986

This comment has been minimized.

Copy link

commented Aug 22, 2015

Hi,
Is working with woocommerce 2.4?
do you have any code for minify js and css automaticly in wordpress? Or reduce number of js/css without plugins?

Thank you

@jfbuildstuff

This comment has been minimized.

Copy link

commented Feb 23, 2016

Super helpful, thanks!

@landsman

This comment has been minimized.

Copy link

commented Aug 1, 2016

Not working with WooCommerce 2.6.4

@pixeline

This comment has been minimized.

Copy link

commented Aug 30, 2016

simply deregister jquery is another, more radical way to go :)

wp_deregister_script('jquery');

@kondasoft

This comment has been minimized.

Copy link

commented Sep 9, 2016

Thanks...

@ikhsanalatsary

This comment has been minimized.

Copy link

commented Oct 25, 2016

Not working with WooCommerce 2.6.4

@cassianotartari

This comment has been minimized.

Copy link

commented Oct 26, 2016

I removed right now some css files using this:

function woocommerce_dequeue_styles( $enqueue_styles ) {
    if ( !is_woocommerce() && !is_cart() && !is_checkout() ) {
        unset( $enqueue_styles['woocommerce-general'] );
        unset( $enqueue_styles['woocommerce-layout'] );
        unset( $enqueue_styles['woocommerce-smallscreen'] );
    }
    return $enqueue_styles;
}
add_filter( 'woocommerce_enqueue_styles', 'woocommerce_dequeue_styles' );

Is in documentation, check it out.

@littlepackage

This comment has been minimized.

Copy link

commented Jun 11, 2019

FWIW the WP 5+ Gutenberg block CSS handle is 'wc-block-style'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.