dequeue (remove) woocommerce css stylesheets

I am trying to dequeue the woocommerce style sheets from all pages except checkout/cart/receipt pages.

The code form the woocommerce help page (http://docs.woothemes.com/document/disable-the-default-stylesheet/) works to remove the stylesheets entirely.

Read More
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );

I tried to use this code but it does not work:

add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ));
if ( function_exists( 'is_woocommerce' ) ) {
    if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
}}
}

Related posts

3 comments

  1. It is because you are checking that the page is not all of it in once. You have to separate the if statements like:

    if ( ! is_woocommerce()) {
      add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
    }}
    if ( ! is_cart() ) {
      add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
    }}
    if ( is_checkout() ) {
      add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
    }}
    

    That should fix your problem.

  2. Change && with ||

        if ( function_exists( 'is_woocommerce' ) ) {
        if ( ! is_woocommerce() || ! is_cart() || ! is_checkout() ) {
    add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
    }}
    

Comments are closed.