Advertisement
lorro

WooCommerce - Exclude child categories

Jun 11th, 2015
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2.   // exclude child categories
  3.   // code goes in functions.php for your child theme
  4.   // credit: http://stackoverflow.com/questions/26711013/hide-subcategories-products-in-the-macro-category-in-woocommerce
  5.   add_filter('pre_get_posts', 'exclude_product_cat_children');
  6.   function exclude_product_cat_children($wp_query) {
  7.     if ( isset ( $wp_query->query_vars['product_cat'] ) && $wp_query->is_main_query()) {
  8.       $wp_query->set('tax_query', array(
  9.          array (
  10.            'taxonomy' => 'product_cat',
  11.            'field' => 'slug',
  12.            'terms' => $wp_query->query_vars['product_cat'],
  13.            'include_children' => false
  14.          )
  15.        )
  16.     );
  17.   }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement