I'm looping through WooCommerce coupons that are restricted to the logged in customer. The problem is that coupons saved with customer restriction have the post_meta "customer_email" sometimes with single values, sometimes with an array. When making a query with WP_QUERY I can't get the coupons that are with the target "customer_email" in array format. Example of my code:
// LOOP ACROSS ALL COUNPONS IN WOOCOMMERCE
$args = array(
'post_type' => 'shop_coupon',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'customer_email',
'value' => array($user_email),
'compare' => 'IN'
),
array(
'key' => 'customer_email',
'value' => $user_email
)
)
);
The code above only returns the coupons that were saved with the customer's email uniquely, the coupons that the same email is in an array are not returned. If someone wonders why the email is saved in the customer_email meta, sometimes as unique and sometimes as an array, it happens because if the coupon is generated as only one email allowed, the value is unique, if it is created with more of an email it is saved as an Array. Any idea why my query doesn't return all the coupons that contain the customer's email?