Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // exclude child categories
- // code goes in functions.php for your child theme
- // credit: http://stackoverflow.com/questions/26711013/hide-subcategories-products-in-the-macro-category-in-woocommerce
- add_filter('pre_get_posts', 'exclude_product_cat_children');
- 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
- )
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement