I’m working on a project that is running of a child theme of TwentySeventeen and whilst the rest of the site doesn’t have a sidebar, WooCommerce seems to have it.
For example, the shop page has it – I have tried a few things already and none work without caveats or didn’t work at all:
I tried copying archive-product.php
to my theme dir in woocommerce/archive-product.php
and removing the below:
do_action( 'woocommerce_after_main_content' );
This didn’t work.
I then tried doing:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
…this didn’t work either.
I found this answer and it worked, but didn’t make the page full width (still had space for the sidebar) and a comment on the answer noted using that method isn’t a great idea.
I also found this answer but it involves adding CSS, something I’d like to avoid as it isn’t the most robust method in-case class names change in the future etc…
Isn’t there a proper way of doing this without potential side affects?
2
Answers
With the help of Mannu saraswat's answer and some fiddling around I came up with a solution:
This avoids having to do the
is_active_sidebar
check / filter addition on non-WooCommerce pages.Maybe there is a cleaner way to do this, but this worked for me.
Please, add this code to your functions.php
For remove only woocommerce side bar
for remove all side bars
OR
You can try this with to increase the priority hope fully its work