Skip to content

Instantly share code, notes, and snippets.

@growdev
Last active February 3, 2022 01:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save growdev/4dba0356178a80abaffd417367a7dbd3 to your computer and use it in GitHub Desktop.
Save growdev/4dba0356178a80abaffd417367a7dbd3 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 ORDER DATA FROM POSTMETA TABLE
delete from wp_postmeta where post_id in (select ID from wp_posts where post_type = 'shop_order');
# DELETE ORDER DATA FROM POSTS TABLE
delete from wp_posts where post_type = 'shop_order';
# DELETE ORDER REFUNDS FROM POSTMETA TABLE
delete from wp_postmeta where post_id in (select ID from wp_posts where post_type = 'shop_order_refund');
# DELETE ORDER REFUNDS FROM POSTS TABLE
delete from wp_posts where post_type = 'shop_order_refund';
# DELETE SUBSCRIPTIONS FROM POSTMETA TABLE
delete from wp_postmeta where post_id in (select ID from wp_posts where post_type = 'shop_subscription');
# DELETE SUBSCRIPTIONS FROM POST TABLE
delete from wp_posts where post_type = 'shop_subscription';
# DELETE scheduled actions
# Note: As of WooCommerce 4.0 Scheduled actions are in custom tables
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 except for administrators
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
);
@pogla
Copy link

pogla commented Dec 25, 2019

payment_retry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment