I am trying to exclude a specific category from my shop overview page. I found the code below which appeared to work for others but does not work on my site. Is there something missing from the code or something I am overlooking?
I tried inserting it into my functions.php file. 9869 is the category ID I am trying to hide.
/**
* This code should be added to functions.php of your theme
**/
add_filter( ‘pre_get_posts’, ‘custom_pre_get_posts_query’ );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
$q->set( ‘tax_query’, array(array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘id’,
‘terms’ => array( 9869 ),
‘operator’ => ‘NOT IN’
)));
remove_filter( ‘pre_get_posts’, ‘custom_pre_get_posts_query’ );
}
Hey web6s,
Thanks for using our theme :)
This article ought help you: https://docs.woocommerce.com/document/exclude-a-category-from-the-shop-page/
Best regards,
John Torvik
Hi! I have the same issue. I want to exclude or hide one specific category in my shop page. This article explain how to exclude products from a specific category, but I want to hide thumbnail and category name
Thanks!
Hey AleFalkinhoff,
Please provide a link to your site, as well as the category you want to hide.
Best regards,
Jordan Shannon
Hi,
Add this to quick css:
.product-category.product.first{
display:none!important;
}
Best regards,
Jordan Shannon
Hi,
Apologies, you can try this method:
https://www.tychesoftwares.com/hide-woocommerce-categories-shop/
Best regards,
Jordan Shannon