Skip to content

Instantly share code, notes, and snippets.

@razajahangir
Last active January 27, 2026 15:59
Show Gist options
  • Select an option

  • Save razajahangir/6d241e2e780105632122f52eb7c58d9b to your computer and use it in GitHub Desktop.

Select an option

Save razajahangir/6d241e2e780105632122f52eb7c58d9b to your computer and use it in GitHub Desktop.
HPOS-compatible SQL query to export active and canceled subscriptions in WooCommerce.
-- Export Active and Canceled Subscriptions (HPOS Compatible)
-- Adjust the table prefix 'wp_' if your database uses a different one, though 'wp_' was detected in wp-config.php.
SELECT
o.id AS subscription_id,
o.status AS subscription_status,
o.date_created_gmt AS date_created,
a.first_name,
a.last_name,
a.email,
o.total_amount,
o.currency
FROM
wp_wc_orders o
INNER JOIN
wp_wc_order_addresses a ON o.id = a.order_id
WHERE
o.type = 'shop_subscription'
AND o.status IN ('wc-active', 'wc-cancelled')
AND a.address_type = 'billing'
ORDER BY
o.id DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment