admin管理员组

文章数量:1130349

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?

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?

本文标签: phpWooCommerce get products based on the taxonomy