Skip to content

Instantly share code, notes, and snippets.

@ifnull
Created October 26, 2021 18:51
Show Gist options
  • Save ifnull/d871ff557a2d44d24ffa75af84324d66 to your computer and use it in GitHub Desktop.
Save ifnull/d871ff557a2d44d24ffa75af84324d66 to your computer and use it in GitHub Desktop.

Revisions

  1. Daniel Smith created this gist Oct 26, 2021.
    3 changes: 3 additions & 0 deletions wc-delete-all-products.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/sh
    wp --user=1 db import ./wc-delete-all-products.sql
    wp --user=1 wc tool run regenerate_product_lookup_tables
    10 changes: 10 additions & 0 deletions wc-delete-all-products.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    DELETE relations.*, taxes.*, terms.*
    FROM wp_term_relationships AS relations
    INNER JOIN wp_term_taxonomy AS taxes
    ON relations.term_taxonomy_id=taxes.term_taxonomy_id
    INNER JOIN wp_terms AS terms
    ON taxes.term_id=terms.term_id
    WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));

    DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
    DELETE FROM wp_posts WHERE post_type IN ('product','product_variation');