Home > database >  Woocommerce how to remove the woocommerce.css file from the theme?
Woocommerce how to remove the woocommerce.css file from the theme?

Time:09-27

I am using WordPress and I installed the Woocommerce plugin.

I added the template folder in my theme and started to customize my theme.

Now, I have to remove the Woocommerce.css from my theme and I found code on the official website here

I added the same code in the function.php

add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );

or

add_filter( 'woocommerce_enqueue_styles', '__return_false' );

but both answers are not working. I have installed the 5.7.1 Woocommerce.

Would you help me out to solve this issue?

CodePudding user response:

Try remove each style one by one:

    add_filter( 'woocommerce_enqueue_styles', 'remove_styles' );
    function remove_styles( $enqueue_styles ) {
        unset( $enqueue_styles['woocommerce-general'] );
        unset( $enqueue_styles['woocommerce-layout'] );
        unset( $enqueue_styles['woocommerce-smallscreen'] );
        return $enqueue_styles;
    }

CodePudding user response:

What you see on the documentation page, no longer works on woo 4 , Here's a link to their github page.

So you need to dequeue its styles!

So if you only want to remove woocommerce.css file, then you could do this:

add_action('wp_enqueue_scripts', 'removing_woo_styles');

function removing_woo_styles()
{
  wp_dequeue_style('woocommerce-general'); // This is "woocommerce.css" file
}

However, if you want to remove all of the style sheets loaded by woo, then you could use this:

add_action('wp_enqueue_scripts', 'removing_woo_styles');

function removing_woo_styles()
{
  wp_dequeue_style('wc-block-vendors-style');
  wp_dequeue_style('wc-block-style');
  wp_dequeue_style('woocommerce-general');
  wp_dequeue_style('woocommerce-layout');
  wp_dequeue_style('woocommerce-smallscreen');
}

This has been fully tested on woocommerce 5 and works fine! If you still can see the styles, then try to clean your cache.

  • Related