Created
January 1, 2021 15:04
-
-
Save SaeedSoltoon/4220c96040cb354c450c3f564a13121b to your computer and use it in GitHub Desktop.
Woocommerce Get All Users Completed Orders Total Mysql Query, Product names concatenated by | and exported to csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT u.ID, | |
u.display_name as fullname, | |
GROUP_CONCAT(oi.order_item_name SEPARATOR ' | ') as courses, | |
SUM(pm2.meta_value) as order_total | |
FROM wp_users as u | |
INNER JOIN wp_posts as p on p.post_status = 'wc-completed' | |
INNER JOIN wp_postmeta as pm on pm.post_id = p.ID | |
and pm.meta_key = '_customer_user' | |
and u.ID = pm.meta_value | |
INNER JOIN wp_postmeta as pm2 on pm2.post_id = p.ID | |
and pm2.meta_key = '_order_total' | |
INNER JOIN wp_woocommerce_order_items as oi on oi.order_id = p.ID | |
and oi.order_item_name NOT LIKE '%specific product name to exclude%' | |
GROUP by u.ID, u.display_name | |
INTO OUTFILE '/var/lib/mysql-files/myorders.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment