Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/5ed1e48bd4b59f1bffdb723f5f9d00c6 to your computer and use it in GitHub Desktop.
Save kimcoleman/5ed1e48bd4b59f1bffdb723f5f9d00c6 to your computer and use it in GitHub Desktop.
MySQL command to export WooCommerce subscription data, including User ID, Product, and Next Payment Date
SELECT
p.ID as 'Subscription ID',
pm1.meta_value as 'User ID',
oitems.order_item_name as 'Product',
pm2.meta_value as 'Next Payment Date'
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_woocommerce_order_items oitems ON oitems.order_id = p.ID
WHERE
post_type = 'shop_subscription'
AND p.post_status = 'wc-active'
AND pm1.meta_key = '_customer_user'
AND pm2.meta_key = '_schedule_next_payment'
AND oitems.order_item_type = 'line_item'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment