Remove WooCommerce Styles and Scripts

I’ve recently started working with WooCommerce for a client. IMHO, it’s 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

https://gist.github.com/jameskoster/7310502#file-functions-php

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

Option 2

https://gist.github.com/gregrickaby/2846416

If you want fine grain control over what appears where, then this function uses a conditional tag to dequeue styles and scripts.

Option 3

https://gist.github.com/gregrickaby/2852142

Kill all the things, forever. You’ll write your own styles, because you’re a fucking ninja.

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.

About Greg Rickaby

Director of Engineering @WebDevStudios / Author & Tech Editor @ForDummies / @WordPress Contributor / @gatsbyjs Maintainer / Follow Greg on Twitter

22 Comments

  1. solosails on May 22, 2013 at 10:46 am

    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

  2. Philipp on May 29, 2013 at 10:41 am

    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.

  3. Jeff on July 8, 2013 at 9:18 am

    Solosails, I prefer to use the following if statement instead:

    if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
    
    }
    • solosails on July 9, 2013 at 6:27 am

      @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

  4. Chirag VoraChirag on December 12, 2013 at 1:09 am

    WPSMITH’s method removed “add to cart” buttons for variations in my store that uses canvas theme.

  5. Jessica Read on December 12, 2013 at 3:46 pm

    Awesome, made my site much faster. Thanks

  6. adam mclane on December 22, 2013 at 5:23 pm

    This is brilliant. Cut my page load time on the homepage from 3-4 seconds to .4 seconds.

  7. Jason Bradley on February 25, 2014 at 11:55 am

    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!

  8. ftntravis on March 23, 2014 at 3:38 pm

    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.

    • Phil on March 27, 2016 at 4:12 pm

      Thanks man! This helped with ‘jquery-blockui’

  9. Corey Light on July 9, 2014 at 2:16 pm

    Thanks for sharing!

  10. Morgan Feeney on September 4, 2014 at 12:40 pm
  11. Tom on May 17, 2015 at 1:53 pm

    Will try this on our ecommerce site right now, thanks!

  12. Hugo dice... on June 24, 2016 at 11:18 am

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

  13. Miryam Flores (@miryamfv) on October 25, 2016 at 3:47 pm

    Thank you!

  14. Andres on November 2, 2016 at 12:26 pm

    Grazie! Perfetto… Thank you!

  15. Anwar on May 9, 2017 at 12:53 pm

    Worked for me – tried a few solutions, but this worked – good stuff

  16. Chris on September 27, 2017 at 12:45 pm

    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!

  17. indextwo on November 10, 2017 at 7:59 am

    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’);

    • Greg Rickaby on November 10, 2017 at 10:10 am

      Thank you sir! I’ve updated the gist…

Leave a Comment