Created
September 15, 2023 12:11
-
-
Save nfsarmento/b98d0640f82d4ccad006fb7a64fb57cc to your computer and use it in GitHub Desktop.
Export ALL subscriptions from WooCommerce Subscriptions using a MySQL query
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 | |
p.ID as 'Subscription ID', | |
p.post_status as 'Subscription Status', | |
pm1.meta_value as 'Billing First Name', | |
pm2.meta_value as 'Billing Last Name', | |
pm3.meta_value as 'Billing Email', | |
oitems.order_item_name as 'Product', | |
pm4.meta_value as 'Order Total', | |
pm5.meta_value as 'Order Tax' | |
FROM wp_posts p | |
INNER JOIN wp_postmeta pm1 ON pm1.post_id = p.ID | |
INNER JOIN wp_postmeta pm2 ON pm2.post_id = p.ID | |
INNER JOIN wp_postmeta pm3 ON pm3.post_id = p.ID | |
INNER JOIN wp_postmeta pm4 ON pm4.post_id = p.ID | |
INNER JOIN wp_postmeta pm5 ON pm5.post_id = p.ID | |
INNER JOIN wp_woocommerce_order_items oitems ON oitems.order_id = p.ID | |
WHERE | |
post_type = 'shop_subscription' | |
AND post_status = 'wc-active' | |
AND pm1.meta_key = '_billing_first_name' | |
AND pm2.meta_key = '_billing_last_name' | |
AND pm3.meta_key = '_billing_email' | |
AND pm4.meta_key = '_order_total' | |
AND pm5.meta_key = '_order_tax' | |
AND oitems.order_item_type = 'line_item' | |
GROUP BY p.ID; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment