• Hi, I wanna see just the products who belong to the same category (and not all the child categories products).
    I tried this code in the child theme functions.php which I’ve found in the internet

    function exclude_product_cat_children($wp_query) {
    	if ( isset ( $wp_query->query_vars['product_cat'] ) && $wp_query->is_main_query()) {
        	$wp_query->set('tax_query', array(
                array (
                    'taxonomy' => 'product_cat',
                    'field' => 'slug',
                    'terms' => $wp_query->query_vars['product_cat'],
                    'include_children' => false
                )
    		) );
      	}
    }

    It works great, until I open the grandchild category and I can’t see his products at all (in every grandchild category.
    Do you know how to change the code in order to see each product for his own sub category?
    Thanks, Itay!

    • This topic was modified 7 years, 5 months ago by itay3000.

The topic ‘Sub category products view’ is closed to new replies.