Skip to content

Instantly share code, notes, and snippets.

@rwkyyy
Last active May 17, 2022 07:08
Show Gist options
  • Save rwkyyy/9b84b6ec25b2901a7db2383ee2a23dfc to your computer and use it in GitHub Desktop.
Save rwkyyy/9b84b6ec25b2901a7db2383ee2a23dfc to your computer and use it in GitHub Desktop.
Clean WooCommerce order/product tables
/*Order*/
DELETE FROM wp_woocommerce_order_itemmeta;
DELETE FROM wp_woocommerce_order_items;
DELETE FROM wp_comments WHERE comment_type = 'order_note';
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';
/*Products*/
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' );
/*Trash*/
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = 'product' AND post_status = 'trash' );
DELETE FROM wp_posts WHERE post_type = 'product' AND post_status = 'trash';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment