I have WooCommerce variable products and a filter which is filtering products based on variation attributes. I have variation attribute depth which has numeric value (from 1 to 20) and the filter is working fine. But I want to display In Stock variations only On the other hand it is displaying all products including out of stock selected depth value (variation). So I want to hide product which will have selected depth value but no stock.
Can I query through Products variation stock ?
Here how it is working right now.
$args = array( 'post_type' => array('product'), 'meta_query' => array( array( 'key' => '_stock_status', 'value' => 'instock', 'compare' => '=', ), ), 'tax_query' => array( array( 'taxonomy' => 'pa_depth', 'field' => 'slug', 'terms' => $wccaf_depth, 'operator' => $wccaf_depth ? 'IN' : 'NOT IN' ) ), );