Answer the question
In order to leave comments, you need to log in
How to make product query on 'instock' status without 'backorders' in Woocommerce?
The store uses three statuses: 'in stock', 'out of stock', 'avaliable for backordrers'. The bottom line is that 'in stock' and 'avaliable for backordrers' items can be added to the cart, but 'out of stock' items cannot. The task is to unload in XML the goods that are only 'instock', but not 'avaliable for backordrers'. The problem is that the 'avaliable for backordrers' status returns the value "instock", as it does for 'in stock' products, respectively, the code:
$query = array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_stock_status',
'value' => 'instock'
)
)
);
$wp_query = & new WP_Query($query);
while ($wp_query->have_posts()) : $wp_query->the_post();
Answer the question
In order to leave comments, you need to log in
If anyone needs...
$query = array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_stock_status',
'value' => 'instock'
),
array(
'key' => '_backorders',
'value' => 'no'
),
)
);
$wp_query = & new WP_Query($query);
while ($wp_query->have_posts()) : $wp_query->the_post();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question