I want to list orders from my Woocommerce shop. I have user meta for my users. (unsubscribed) I only want to list the order if that order's user is unsubscribed === 0.
I have working code to the customers:
$args = array(
'role' => 'customer',
'number' => - 1,
'meta_query' => [
'relation' => 'OR',
[
'key' => 'unsubscribed',
'compare' => '!=',
'value' => 1
],
[
'key' => 'unsubscribed',
'value' => 0,
'compare' => 'NOT EXISTS'
]
],
);
$query = new WP_User_Query( $args );
I would like to do similar query with wc_get_orders
but it doesn't work:
$args = [
'limit' => - 1,
'meta_query' => [
'relation' => 'OR',
[
'key' => 'unsubscribed',
'compare' => '!=',
'value' => 1
],
[
'key' => 'unsubscribed',
'value' => 0,
'compare' => 'NOT EXISTS'
]
]
];
$orders = wc_get_orders( $args );