Last updated on September 13, 2023

Remove WooCommerce CSS

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Remove the default WooCommerce CSS.

WooCommerce is a popular plugin for WordPress that adds e-commerce functionality to your website. If you are working with WooCommerce in WordPress, you may notice that WooCommerce adds a lot of styles to your site. While these styles can be helpful for simple webshops, you may want to remove some of them if they conflict with your theme’s styles or if they are simply unnecessary. Here’s how to remove the WooCommerce CSS:

function wpsnippets_dequeue_woocommerce_styles() {

    if ( class_exists( 'woocommerce' ) ) {
        wp_dequeue_style( 'woocommerce-general' );
        wp_dequeue_style( 'woocommerce-layout' );
        wp_dequeue_style( 'woocommerce-smallscreen' );
        wp_dequeue_style( 'woocommerce_frontend_styles' );
        wp_dequeue_style( 'woocommerce_fancybox_styles' );
        wp_dequeue_style( 'woocommerce_chosen_styles' );
        wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
    }
}

add_action( 'wp_enqueue_scripts', 'wpsnippets_dequeue_woocommerce_styles', 99 );

To remove (dequeue) the default WooCommerce CSS styles in WordPress, you can use the wp_dequeue_style function along with the wp_enqueue_scripts action hook. In this code snippet, we define a function wpsnippets_dequeue_woocommerce_styles that uses the wp_dequeue_style function to remove the default WooCommerce styles. We check if the woocommerce class exists to ensure that the styles are only removed if WooCommerce is active. Finally, we hook this function to the wp_enqueue_scripts action with a priority of 99, which ensures that it is loaded after the default WooCommerce styles are enqueued.

You can modify this code snippet to remove only specific styles, or to remove styles from other plugins or themes by changing the style handles used in the wp_dequeue_style function. Additionally, you can modify the priority of the add_action function to ensure that the styles are dequeued at the appropriate time.

Last updated on September 13, 2023. Originally posted on May 9, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *