Skip to content

Instantly share code, notes, and snippets.

@luiseduardobraschi
Last active August 30, 2019 22:46
Show Gist options
  • Save luiseduardobraschi/def4c0e06dd68c826d4787b4c23d6f5e to your computer and use it in GitHub Desktop.
Save luiseduardobraschi/def4c0e06dd68c826d4787b4c23d6f5e to your computer and use it in GitHub Desktop.
[WooCommerce BR] Get orders from user by ID or e-mail
SELECT wp_posts.* FROM wp_posts
INNER JOIN wp_users AS users ON users.user_email = 'EMAIL_YOU_WANT'
INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE 1=1
AND wp_postmeta.meta_key = '_customer_user'
AND wp_postmeta.meta_value = users.ID
AND wp_posts.post_type = 'shop_order'
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC
SELECT wp_posts.* FROM wp_posts
INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE 1=1
AND wp_postmeta.meta_key = '_customer_user'
AND wp_postmeta.meta_value = 'ID_YOU_WANT'
AND wp_posts.post_type = 'shop_order'
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment