I am creating a clothing store. The clothing are variable products based on size (xs, s, m, l, xl etc..). I am trying to create filters to display products that are in stock, based on a filter. So, clicking the "xs" filter should show products that both have the XS variation, and have that variation in stock.
So far, I've got something like this:
$query_args = array(
'post_type' => 'product', 'product_variation',
'posts_per_page' => 12,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'pa_sizes',
'field' => 'term_id',
'terms' => 'xs',
),
),
'meta_query' => array(
array(
'key' => '_stock_status',
'value' => 'outofstock',
'compare' => '='
),
)
);
$query = new WP_Query($query_args);
I know right now it's searching for "outofstock" but that was just a test, and not even this comes up with any products, even though I have created some products with some sizes out of stock.