How to Bulk Remove WooCommerce Products, Categories, and Images in phpMyAdmin
If you’re looking to clean up your store and bulk remove WooCommerce products, categories, and product images, while keeping your orders and settings intact, you can do so by executing a few SQL queries in phpMyAdmin.
Important: Before proceeding, make sure to backup your database to prevent any accidental loss of data.
Interesting Post: How to Backup Your Database in cPanel, DirectAdmin, and Webmin/Virtualmin
Below is the SQL code you can use:
-- Delete product images
DELETE attachments
FROM wp_posts AS attachments
INNER JOIN (
SELECT meta.meta_value AS attachment_id
FROM wp_postmeta AS meta
WHERE meta.meta_key = '_thumbnail_id'
AND meta.post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))
) AS subquery ON attachments.ID = subquery.attachment_id
WHERE attachments.post_type = 'attachment';
-- Delete product taxonomy terms
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 product meta
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
-- Delete products
Note: Replace wp_ with your actual database prefix if it’s different.
To execute these queries, follow these steps:
Bulk Remove WooCommerce Products
- Log in to your phpMyAdmin dashboard.
- Select your WordPress database from the left sidebar.
- Click on the SQL tab at the top.
- Paste the above code into the SQL query box.
- Click on the “Go” or “Run” button to execute the queries.
Bulk Remove WooCommerce Products



