skip to Main Content

I have a WordPress problem that I can’t fix….

Woocommerce is using a sidebar with product filters.

I’d simply like to hide the sidebar + filters on Woocommerce parent pages.

I first tried by adding a class which I could hide the sidebar content with css, like this :

add_filter( 'fusion_sidebar_1_class', 'usl_wc_product_cats_css_body_class' );

function usl_wc_product_cats_css_body_class( $classes )
    {
        if( is_tax( 'product_cat' ) ) {
        $cat = get_queried_object();
        if( 0 == $cat->parent  ) $classes[] = 'usl-parent';
}
return $classes;
}

But this obviously leaves the main content at 80% or so.

So I’m now trying to remove the sidebar instead using a mix of the above and some example code from the Avada help pages. Code is below but totally doesn’t work! Can anyone please help?

function remove_woo_commerce_sidebar() {
    global $avada_woocommerce;
    {
    if( is_tax( 'product_cat' ) ) 
        {
          $cat = get_queried_object();
          if( 0 == $cat->parent  )  
          remove_action( 'woocommerce_sidebar', array( $avada_woocommerce, 'add_sidebar' ), 10 );
        }        
    }

add_action( 'after_setup_theme', 'remove_woo_commerce_sidebar' );

2

Answers


  1. Chosen as BEST ANSWER

    Couldn't find a neat way to unload the sidebar so added an extra body class so I could target both the main content & sidebar with this :

    add_filter( 'body_class','usl_body_classes' );
    
    function usl_body_classes( $classes ) 
        {
            if( is_tax( 'product_cat' ) ) {
            $cat = get_queried_object();
            if( 0 == $cat->parent  ) $classes[] = 'usl_full_woo_css';
        }
        return $classes;    
    }
    

  2. Can’t you just do this through CSS? Just change the selector to match the page type you want to affect

    .woocommerce-page #content .single_wrap {
    float: none;
    width: 100%;
    }
    
    .woocommerce-page #sidebar {
        display: none;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search