I need to modify the WooCommerce product query because I want to filter the shown products on the shop pages based on the taxonomies for each product. So what I've tried is this here:

add_filter( 'woocommerce_product_query_meta_query', 'filter', 10, 2 );
function filter( $meta_query, $query ) {
    // Only on category pages
    if ( ! is_product_category() ) {
        return $meta_query;

    $tags_array[] = 'ABCSD';

    $meta_query[] = array(
        'key'     => 'product_tag',
        'value'   => $tags_array,
        'compare' => 'EXIST'

    return $meta_query;

So I just want to display all products which have the taxonomy ABCSD in it. The code is placed in my functions.php. What I'm doing wrong here?

  • You should use the woocommerce_product_query_tax_query filter, and check here if you need help with taxonomy queries (i.e. tax_query). I'd also rename '$meta_query' to '$tax_query' since the latter is more relevant... – Sally CJ Dec 7 '18 at 0:35
  • This might also help: stackoverflow.com/questions/33667469/… – Nathaniel Flick Dec 7 '18 at 0:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.