Reset WooCommerce: Delete All Products, Attributes & Categories with SQL
A complete WooCommerce catalog cleanup using targeted SQL queries to delete products, variations, attributes and product categories directly from the database.
What this SQL snippet does
Sometimes you need to completely reset your WooCommerce store, especially when testing imports, starting fresh with a new feed or cleaning up a staging website.
WooCommerce does not provide a built-in one-click option to instantly delete all products, product attributes and categories. With the following SQL queries, you can perform a fast and targeted database cleanup.
1) Why reset WooCommerce with SQL?
A SQL reset is useful when you need a clean WooCommerce environment without manually bulk-deleting records from the WordPress admin.
- Quick and clean database reset.
- Ideal for staging or development environments.
- Useful when replacing supplier product feeds.
- Helpful when a broken import has created incorrect or duplicate products.
- Faster than manually deleting products, attributes and categories from the admin area.
2) Before running the queries
Before deleting anything directly from the database, make sure you have a valid backup and that you are using the correct WordPress table prefix.
- Take a full database backup.
- Test the queries on a staging environment first.
- Replace
XvvIa4v_with your real WordPress table prefix. - Check the table prefix inside your
wp-config.phpfile. - Do not run this on a live site unless you are absolutely sure.
- After the cleanup, clear cache and WooCommerce transients.
3) Code Snippets
Run the following SQL queries through phpMyAdmin, Adminer,
a MySQL client or wp db query. Before running them, replace
XvvIa4v_ everywhere with the table prefix of your own WordPress site.
DELETE p, pm, tr
FROM XvvIa4v_posts AS p
LEFT JOIN XvvIa4v_postmeta AS pm ON p.ID = pm.post_id
LEFT JOIN XvvIa4v_term_relationships AS tr ON p.ID = tr.object_id
WHERE p.post_type IN ('product', 'product_variation');
DELETE t, tt, tr
FROM XvvIa4v_terms AS t
JOIN XvvIa4v_term_taxonomy AS tt ON t.term_id = tt.term_id
LEFT JOIN XvvIa4v_term_relationships AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
WHERE tt.taxonomy LIKE 'pa_%';
DELETE t, tt, tm
FROM XvvIa4v_terms AS t
INNER JOIN XvvIa4v_term_taxonomy AS tt ON t.term_id = tt.term_id
LEFT JOIN XvvIa4v_termmeta AS tm ON t.term_id = tm.term_id
WHERE tt.taxonomy = 'product_cat';
4) How it works
product and
product_variation post types, along with their related post meta and taxonomy relationships.
pa_, such as pa_color, pa_size and similar attributes.
product_cat.
5) Where to run the queries
Depending on your hosting environment and access level, you can run these SQL queries in one of the following ways.
- phpMyAdmin: from the SQL tab of your database.
- Adminer: if you use a lightweight database management tool.
- WP-CLI: through
wp db query, if you have SSH access. - MySQL client: directly from the terminal for more advanced usage.
6) What to check after the reset
After the cleanup is complete, run a quick check to confirm that your WooCommerce catalog has been cleaned correctly.
- Open WooCommerce β Products and confirm that no products remain.
- Check the product categories screen.
- Check product attributes from Products β Attributes.
- Clear cache from your cache plugin or server.
- Clear WooCommerce transients if needed.
- Run a small test import before importing the full product feed.
7) Best Practices
- Always back up the database before running SQL queries.
- Test the process on a staging environment first.
- Replace
XvvIa4v_with your real table prefix. - Use these queries only when you need a full WooCommerce catalog reset.
- Do not use them for deleting individual products.
- After the reset, import products from a clean and trusted file or feed.
8) Frequently Asked Questions
No. These queries target products, variations, attributes and product categories. They do not delete orders or customers.
Not with these queries. Product records are deleted, but media attachments are not automatically removed from the WordPress media library.
Not directly. You can restore the deleted data only from a database backup.
Yes. The example uses XvvIa4v_. You must replace it with the real
prefix of your WordPress site.
Only if you want to completely clean the WooCommerce catalog and you have a verified backup. For normal product management, use a safer admin-based method.
9) Support
For any issue or question related to WooCommerce SQL snippets, you can contact technical support.