Skip to content

Instantly share code, notes, and snippets.

@kurtschlatzer
Forked from growdev/remove_wc_data.sql
Created January 3, 2019 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtschlatzer/871b7ffeed5de8251f44525b82922786 to your computer and use it in GitHub Desktop.
Save kurtschlatzer/871b7ffeed5de8251f44525b82922786 to your computer and use it in GitHub Desktop.
Remove WooCommerce orders, subscriptions, non admin users
# GET number of orders
select count(*)from wp_posts where post_type = 'shop_order';
# DELETE ORDERS
delete from wp_postmeta where post_id in (
select ID from wp_posts where post_type = 'shop_order');
delete from wp_posts where post_type = 'shop_order';
# DELETE order refunds
delete from wp_postmeta where post_id in (
select ID from wp_posts where post_type = 'shop_order_refund');
delete from wp_posts where post_type = 'shop_order_refund';
# DELETE subscriptions
delete from wp_postmeta where post_id in (
select ID from wp_posts where post_type = 'shop_subscription');
delete from wp_posts where post_type = 'shop_subscription';
# DELETE scheduled actions
delete from wp_postmeta where post_id in (
select ID from wp_posts where post_type = 'scheduled-action');
delete from wp_posts where post_type = 'scheduled-action';
# DELETE users
delete from wp_users where ID not in (
select user_id
from wp_usermeta
where meta_value like '%administrator%'
);
delete from wp_usermeta where user_id not in (
select ID from wp_users
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment