Skip to content
ThemesCraft.

Putting WooCommerce on a CSS Diet

Woo ships a lot of stylesheet for pages that aren't shops. Here's how we conditionally load it and what broke when we got it wrong.

Putting WooCommerce on a CSS Diet

On a content-heavy site with a small shop, WooCommerce's default styles load on every page — including the ones with nothing to sell.

Dequeue, then re-enqueue deliberately

add_filter( 'woocommerce_enqueue_styles', function ( $styles ) {
    if ( is_woocommerce() || is_cart() || is_checkout() ) {
        return $styles;
    }
    return [];
} );

The trap: mini-cart widgets and product blocks placed in a footer or on a landing page. Check for those blocks before you strip the styles, or you'll ship an unstyled cart to the one page that converts.

Results

182kb removed from every non-shop page, and a 0.4s improvement in Largest Contentful Paint on the blog index.