daily pastebin goal
3%
SHARE
TWEET

WooCommerce - Exclude child categories

lorro Jun 11th, 2015 (edited) 228 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top