Skip to content

Instantly share code, notes, and snippets.

@growdev
Last active February 3, 2022 01:52
Show Gist options
  • Save growdev/4dba0356178a80abaffd417367a7dbd3 to your computer and use it in GitHub Desktop.
Save growdev/4dba0356178a80abaffd417367a7dbd3 to your computer and use it in GitHub Desktop.

Revisions

  1. growdev revised this gist Jul 22, 2020. 1 changed file with 16 additions and 12 deletions.
    28 changes: 16 additions & 12 deletions remove_wc_data.sql
    Original file line number Diff line number Diff line change
    @@ -2,27 +2,31 @@
    # 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 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
    delete from wp_postmeta where post_id in (
    select ID from wp_posts where post_type = 'shop_order_refund');
    # 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
    delete from wp_postmeta where post_id in (
    select ID from wp_posts where post_type = 'shop_subscription');
    # 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
    delete from wp_postmeta where post_id in (
    select ID from wp_posts where post_type = 'scheduled-action');
    # 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
    # DELETE users except for administrators
    delete from wp_users where ID not in (
    select user_id
    from wp_usermeta
  2. growdev revised this gist Apr 17, 2018. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions remove_wc_data.sql
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,33 @@

    # GET number of orders
    select count(*)from wp_posts where post_type = 'shop_order'
    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'
    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'
    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'
    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'
    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
    )
    );
  3. growdev created this gist Mar 9, 2018.
    33 changes: 33 additions & 0 deletions remove_wc_data.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@

    # 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
    )