Sidebar for only WooCommerce pages (archives, categories)

Dear,

My website has a blog and a shop. For all the product pages I want the sidebar to display filters / search / etc (proudct widgets) and for all the blog posts/archives/index I want to show the blog sidebar (categories, top comments, etc).

I have made my “main sidebar” the “blog sidebar” and I have created a new sidebar “Shop” for which I ticked the box ‘make shop sidebar’

HOWEVER

This only activates my shop sidebar for the shop index page (where I don’t need it, this page is full width for me) but on the product categories the blog sidebar (i.e. the main sidebar) is still displayed.

How can I set this up the way I intended? (shop sidebar for all shop pages, blog sidebar for all blog pages) without having to select every individual taxonomy.

Thanks!

1 Like

Hi,

To achieve that you can add the code below in your child theme’s functions.php file


add_filter( 'ups_sidebar', 'assign_sidebars' );

function assign_sidebars($sidebar){
if(x_is_product()){
    return 'ups-sidebar-shop-sidebar';
}

if (is_singular('post')) {
	return 'ups-sidebar-blog-sidebar';	
}
return $sidebar;
}

Make sure to change ups-sidebar-shop-sidebar and ups-sidebar-blog-sidebar with your corresponding sidebar

Thanks

Thanks for the reply, I added the code but it’s not working. The main sidebar is still displayed.

The code can be changed to just the if-case for the product, as the “blog sidebar” can be the “main sidebar”.

I’ll add a secure note

Hello There,

Thanks for updating in! I have logged in and updated your code with this:

// Shop sidebar for Woocommerce producs
add_filter( 'ups_sidebar', 'assign_sidebars' );

function assign_sidebars($sidebar){
	if( x_is_shop() || x_is_product_category() || is_product_tag() ){
    	return 'ups-sidebar-shop';
	}

	return $sidebar;
}

x_is_shop() || x_is_product_category() || is_product_tag() is a condition to determine if it is the shop page, category page or the product tag page.

You can now view the sidebar in the product category pages.

1 Like

Awesome, this worked. Thanks a lot for the stellar support you deliver!

Sure @yvescleeren, you are welcome :slight_smile:

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.