I’m trying to display the Woocommerce nav filters on the home page so visitors can filter all the shop products from any page (when they hit the filter they will be taken to the shop page as usual). What I wanted is to include it on the header to accomplish this but it doesn’t work.
To my understanding it loads only when the shop loop is loaded. I tried to do a custom loop but that didn’t work.
I didn’t found any documentation at all on how to do this. So here comes the work arround that worked for me.
Register a sidebar in the functions.php file (you can change the name to whatever you want):
At the end of the functions.php file:
After that Create a folder inside your template named
cache-woocommerce-nav-filter
In the template page you want to display the custom filters (our sidebar in this case is named filters-sidebar but can be change to anything else:
look for this piece of code in wp-content/plugins/woocommerce/classes/widgets
AND REMOVE IT.
Yur widget should now display on every page
I have just had the same problem, and here is how I solved it. As the OP stated, the real problem here is that WC filters work only when the main query is loaded with the products. So, calling
do_action( 'woocommerce_sidebar' );
without proper globalWP_Query
andWC_Query
loaded will most often do nothing.So I created this helper function:
Now, on every page template you want to display your sidebar, just call this function:
wpse112648_woo_sidebar()