Looking solution for Exclude particular category products from display on shop and Category archive page ?
In following example you will get idea how you able to hide particular category products from not display on WooCommerce Shop and Category archive page.
To Hide Specific Category products from Shop page and Product archive page add following code in your active theme functions.php and dont forgot to replace “hide category slug” by your Category slug, Category that products you dont want to show on WooCommerce Shop page.
# Exclude particular category products from WooCommerce Shop and Category archive 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( 'hide category slug' ), // Set Category Slug which products not show on the shop and Archieve page. 'operator' => 'NOT IN' ); $q->set( 'tax_query', $tax_query ); } add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' ); #
Exclude Product Category from WP_Query in WooCommerce
$args = array( 'post_type' => 'product', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'hide category slug' ), 'operator' => 'NOT IN' ) ) ); query_posts($args);
Exclude particular category from Shop page
add_filter( 'get_terms', 'fn_get_subcategory_terms', 10, 3 ); function fn_get_subcategory_terms( $terms, $taxonomies, $args ) { $new_terms = array(); if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) { foreach ( $terms as $key => $term ) { if ( ! in_array( $term->slug, array( '**CATEGORY-HERE**' ) ) ) { $new_terms[] = $term; } } $terms = $new_terms; } return $terms; }