How to exclude products from child categories in WooCommerce Products Filter plugin.

Imagine you need to count only the number of products in current category. By default, WooCommerce Products Filter plugin for WordPress also count all products in child categories.

To achieve this, just hook to the woocommerce_shortcode_products_query filter and change include_children value to 0 in tax_query.

Just add the following code to <code>functions.php</code> file of your active theme:

function filter_woocommerce_shortcode_products_query( $array ) { 
 foreach ($array['tax_query'] as $key => $value){
  $array['tax_query'][$key]['include_children'] = 0;
 }
 return $array; 
}; 

add_filter( 'woocommerce_shortcode_products_query', 
 'filter_woocommerce_shortcode_products_query', 10, 1 );