WooCommerce SQL Snippet

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.

WooCommerce SQL Cleanup Staging Reset
Reset WooCommerce with SQL

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.

Products & variations Deletes all WooCommerce products and product variations.
Attributes Removes product attributes such as color, size and other pa_ taxonomies.
Product categories Cleans WooCommerce product categories and their term meta.

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.
This process is destructive and should not be used for routine product maintenance.

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.php file.
  • Do not run this on a live site unless you are absolutely sure.
  • After the cleanup, clear cache and WooCommerce transients.
These queries do not have an β€œundo” option. Recovery is possible only through a database backup.

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.

Remove All Products and Variations.sql
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');
Remove All Attributes.sql
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_%';
Remove All Product Categories.sql
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';
The queries are split into three steps so you can control what gets deleted at each stage.

4) How it works

It deletes products and variations The first query targets the product and product_variation post types, along with their related post meta and taxonomy relationships.
It deletes product attributes The second query removes WooCommerce attribute taxonomies that start with pa_, such as pa_color, pa_size and similar attributes.
It deletes product categories The third query deletes terms, term taxonomy records and term meta that belong to product_cat.
It leaves a clean WooCommerce catalog After running the queries, WooCommerce will no longer have products, attributes or product categories.

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.
On large WooCommerce sites, run database cleanup operations during low-traffic hours.

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

Will this delete all orders?

No. These queries target products, variations, attributes and product categories. They do not delete orders or customers.

Will this delete product images?

Not with these queries. Product records are deleted, but media attachments are not automatically removed from the WordPress media library.

Can I undo the deletion?

Not directly. You can restore the deleted data only from a database backup.

Do I need to change the table prefix?

Yes. The example uses XvvIa4v_. You must replace it with the real prefix of your WordPress site.

Is this suitable for a live 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.

info@vgdevsolutions.gr

Related posts