diff --git a/lib/Segments/DynamicSegments/Filters/WooCommerceCountry.php b/lib/Segments/DynamicSegments/Filters/WooCommerceCountry.php index 1091ab9905..7380d69faa 100644 --- a/lib/Segments/DynamicSegments/Filters/WooCommerceCountry.php +++ b/lib/Segments/DynamicSegments/Filters/WooCommerceCountry.php @@ -27,10 +27,14 @@ class WooCommerceCountry implements Filter { $subscribersTable, $wpdb->postmeta, 'postmeta', - "postmeta.meta_key = '_customer_user' - AND $subscribersTable.wp_user_id=postmeta.meta_value - AND postmeta.post_id NOT IN ( SELECT id FROM {$wpdb->posts} as p WHERE p.post_status IN ('wc-cancelled', 'wc-failed'))" - )->innerJoin('postmeta', + "postmeta.meta_key = '_customer_user' AND $subscribersTable.wp_user_id=postmeta.meta_value" + )->innerJoin( + 'postmeta', + $wpdb->posts, + 'posts', + "postmeta.post_id = posts.id AND posts.post_status NOT IN ('wc-cancelled', 'wc-failed')" + )->innerJoin( + 'postmeta', $wpdb->postmeta, 'postmetaCountry', "postmeta.post_id = postmetaCountry.post_id AND postmetaCountry.meta_key = '_billing_country' AND postmetaCountry.meta_value = :$countryFilterParam"