Woocommerce returns Product post_status as published even tho it is in status draft

Question

Heyho,

I’ve got a problem getting the post_status of a WP_PostObject which is a Woocommerce-Product.
I get all products doing this query:

$onlineShopProducts = get_posts([
            'post_type' => ['product', 'product_variation'],
            'orderby' => 'post_title',
            'order' => 'ASC',
            'numberposts' => -1
        ]);

Now I want to filter out all products which are in status draft during a foreach-loop:

foreach ($onlineShopProducts as $onlineShopProduct){
            if($onlineShopProduct->post_status != 'publish'){
                continue;
            }
            doSomething($onlineShopProduct)
        }

but $onlineShopProduct->post_status and get_post_status($onlineShopProduct->ID) both return "publish", even tho they are set "Draft" in the product-edit-view… (it’s in german)

enter image description here

is there some sort of post_meta I have to query or is this a know bug of some sort? How can I filter out the drafted products?

Greetings

0
Husky110 8 months 2020-12-14T06:10:27-05:00 0 Answers 12 views 0

Leave an answer

Browse
Browse