Woocommerce returns Product post_status as published even tho it is in status draft
The solution is simple, delete the if check you’re having problems and add the post_status parameter to get_posts. For example: $args = [ ‘post_status’ => ‘publish’, ]; $only_published_posts = get_posts( $args ); Likewise we can pass an array of the statuses we do want, e.g. $args = [ ‘post_status’ => [ ‘publish’, ‘pending’ ], ]; … Read more