How can i hide some categories products on the shop page
Md Abul Bashar | 5,918 views | November 15, 2016 | WooCommerce,WordPress | No | 10:18 AM |
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.
You have to enjoy this articel? Don't forget subscribes this site.
If you want to get our update article, then please subscribe this site.
This title last post
5,918 views | November 15, 2016 | 10:18 AM