How to Bulk Remove WooCommerce Products, Categories, and Images in phpMyAdmin

How to Bulk Remove WooCommerce Products, Categories, and Images in phpMyAdmin

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:
  1. Log in to your phpMyAdmin dashboard.
  2. Select your WordPress database from the left sidebar.
  3. Click on the SQL tab at the top.
  4. Paste the above code into the SQL query box.
  5. Click on the “Go” or “Run” button to execute the queries.
After executing these queries, all your products, categories, and product images will be removed from your WooCommerce store, leaving your orders and settings intact. Remember, always backup your database before making any changes.
Bulk Remove WooCommerce Products
Bulk Remove WooCommerce Products
Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *