Hiding Categories From Shop Page
-
Hi,
I want to make two store sections.
1. Individual products (Main store page)
2. Gift kits / Product combos (Category page)I have added following code to the child theme’s functions.php to hide gift kits category and related products from store page.
Hide Gift Kits category from store page
add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 ); function ts_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( 'gift-kits' ) ) ) { $new_terms[] = $term; }} $terms = $new_terms; } return $terms; }
Exclude products from a Gift Kits category on the shop 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( 'gift-kits' ), 'operator' => 'NOT IN' ); $q->set( 'tax_query', $tax_query ); } add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
Now the problem is when I visit Gift Kits category page, I can’t even see related products there. It shows “No products were found matching your selection.”
Please suggest the changes in above code so Gift Kits will be shown on that category page only.
Also I want to hide sidebar from the gift kits category page as it shows other categories there. If not this, then is there any option I can hide only categories filter and keep pricing filter?
The page I need help with: [log in to see the link]
- The topic ‘Hiding Categories From Shop Page’ is closed to new replies.