Skip to content

Instantly share code, notes, and snippets.

@brunomarks7
Last active August 7, 2024 01:20
Show Gist options
  • Save brunomarks7/9291631645bc6ec3152389808fe37f03 to your computer and use it in GitHub Desktop.
Save brunomarks7/9291631645bc6ec3152389808fe37f03 to your computer and use it in GitHub Desktop.
Select customer emails from WooCommerce
SELECT DISTINCT pm.meta_value AS email
FROM wp_posts AS p
INNER JOIN wp_postmeta AS pm ON p.ID = pm.post_id
INNER JOIN wp_woocommerce_order_items AS oi ON p.ID = oi.order_id
INNER JOIN wp_woocommerce_order_itemmeta AS oim ON oi.order_item_id = oim.order_item_id
WHERE p.post_type = 'shop_order'
AND p.post_status IN ('wc-completed', 'wc-processing')
AND pm.meta_key = '_billing_email'
AND oim.meta_key = '_product_id'
AND p.post_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment