How to hide any Products from Woocommerce Shop Page?
-
Hi!
I have two products in two category. I designed the shop page in Visual Editor and put my product’s images. I want to hide the products but keep the page as a shop page. How can I remove all the woocommerce products from the shop page?As I have only two categories, I used the below code in my functions.php but not working.
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() ) { $q->set( 'tax_query', array(array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'cat-slug-1','cat-slug-2' ), 'operator' => 'NOT IN' ))); } remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to hide any Products from Woocommerce Shop Page?’ is closed to new replies.