How can i hide some categories products on the shop page


Hello every0ne, toady i will share how to hide some categories products in shop page from your woocommerce website.

It’s easy to work, just you need to write one function in your function page.

add_action( '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;

if ( ! is_admin() && is_shop() && ! is_user_logged_in() ) {

$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'shirt', 'tshirt', 'pant' ), //Category name which not to want display products on the shop page
'operator' => 'NOT IN'


remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );


Category name(‘shirt’, ‘tshirt’, ‘pant’) which not to want display products on the shop page


Just you can save your page then check,

If you see show any error then you can remove this code from above code lists.

remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

if you need any help just comment below this post. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!

%d bloggers like this: