WooCommerce is absolutely the most brilliant and easy-to-use shopping cart for WordPress – but it’s heavy! I’ll show you how to remove the cruft!
Option 1: Use a filter
There are a couple of ways to do this. The easiest is to remove the three primary stylesheets using a simple filter in functions.php
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
Option 2: A bit more control
If you want fine grain control over what appears where, then this function uses a conditional tag to dequeue styles and scripts.
/**
* 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 );
Option 3: Nuke it
Kill all the things, forever. You’ll write your own styles, because you’re a fucking ninja.
/**
* Remove all WooCommerce scripts and styles! Forever!
*/
function grd_remove_woocommerce_styles_scripts() {
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
remove_action( 'wp_enqueue_scripts', array( $GLOBALS['woocommerce'], 'frontend_scripts' ) );
}
define( 'WOOCOMMERCE_USE_CSS', false );
add_action( 'init', 'grd_remove_woocommerce_styles_scripts', 99 );
Further reading:
WooCommerce has a page dedicated for style & script management. Also, take a look at the PHP Class responsible for enqueuing styles and scripts.
Thanks to everyone who’s suggested things in the comments. Peer code-review is amazing, and it’s why I share this stuff.
It’s fantastic, thanks, speeds up home page no end and stopped the ridiculous ajax calls.
One question, how would one go about adding this to other pages that dont require the woocommerce bloat code?
Thanks again
Use conditional tags: http://codex.wordpress.org/Conditional_Tags
Mhh all codes from your site and in the comment doesn’t work. I’ve changed the ‘ with the correct ‘. Must I change something for my template? I use superstore from woocommerce. Thanks for help.
Solosails, I prefer to use the following if statement instead:
@Jeff, Thank you for that, I was aware that the way I did it was pretty clunky, but it shows my lack of knowledge in coding!
Cheers All
WPSMITH’s method removed “add to cart” buttons for variations in my store that uses canvas theme.
Awesome, made my site much faster. Thanks
This is brilliant. Cut my page load time on the homepage from 3-4 seconds to .4 seconds.
This just came in very handy! Just an FYI, since the latest release of WooCommerce, some of the styles and scripts names changed, so you might want to update them. Here’s where you can find them: http://docs.woothemes.com/wc-apidocs/source-class-WC_Frontend_Scripts.html#55
Thanks again for sharing!
Been pulling my hair out trying to dequeue “wc-add-to-cart-variation” javascript. If anyone else is having this problem add the following to the function above: wp_deregister_script(‘wc-add-to-cart-variation’);
Deregistering it will remove it completely.
Thanks man! This helped with ‘jquery-blockui’
Thanks for sharing!
Hey guys, don’t you know about this: http://docs.woothemes.com/document/disable-the-default-stylesheet/
Will try this on our ecommerce site right now, thanks!
Hi, you really save my day man, I’m crying of joy!! With the new woocommerce update, I was having a lot of problems with ajax, but I could solved everything thanks to your post. Tks Tks Tks Tks forever !!!
Thank you!
Grazie! Perfetto… Thank you!
Worked for me – tried a few solutions, but this worked – good stuff
Hey Greg we were inspired by your code to make a free plugin:
https://wordpress.org/plugins/disable-wc-styles-littlebizzy/
Disable WooCommerce Styles
Even credited you. Thanks!
Thanks Chris!
Since this is a pretty high-ranking article, I thought I’d add in this: Select2 as a library has effectively been abandoned, so as of WooCommerce 3.2x they added SelectWoo, which is a fork of the original Select2 with some Woo-specific stuff in there. As this is now enqueued under a different handle (but still basically throws in Select2-classed DOM elements), you might notice that if you’ve dequeued Select2 but NOT SelectWoo, then your country dropdown field might look weird. Easy solution: dequeue SelectWoo:
wp_dequeue_script(‘selectWoo’);
wp_deregister_script(‘selectWoo’);
Thank you sir! I’ve updated the gist…