A
A
asunaro_ru2016-03-25 16:31:14
XML
asunaro_ru, 2016-03-25 16:31:14

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();

unloads all these goods. How to exclude 'avaliable for backordrers' goods from unloading?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
asunaro_ru, 2016-03-25
@asunaro_ru

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 question

Ask a Question

731 491 924 answers to any question