Archived topic
Woocommerce exclude products from shop - workshops
5 replies · Started by _blank on June 6, 2018
Hi
I’m trying to remove 2 categories from the shop landing page using a PHP snippet from woocommerce.
https://docs.woocommerce.com/document/exclude-a-category-from-the-shop-page/
The 2 product categories/slugs are events and workshops
The snippet is here:
/**
* Exclude products from a particular category on the shop page
*/
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'workshops' ), // Don't display products in the workshops category on the shop page.
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
Hi there,
So the code isn't working?
Have you checked with WooCommerce' support on this?
The code is from them.
Hi Leo
I had a look but can't find support options for their free plugins. Will try to contact them again.
Do you have any ideas/suggestions on how I might achieve the same results. I'm using Beaver Builder to display the Categories.
Thanks
Scott
Hi Scott, i tried the code for a single category on a non pagebuilder shop and it works. So must be a BB thing. Woo don't really provide support for their free stuff. If you're using the BB module, then this may help:
https://kb.wpbeaverbuilder.com/article/79-woocommerce-module-overview#multiple-products
Hi David
Thats really helpful - I'll contact BB and try a GP page as well for the Shop.
Scott
You're welcome Scott.