Deleting all products from WooCommerce via the database is a task that requires caution. If you are not careful, you can cause irreparable damage to your database. It is strongly recommended that you create a full backup of your database before making any changes.
Here's how to delete all products using phpMyAdmin, a widely used database management tool in WordPress hosting environments:
- Database backup: Before taking any further steps, back up your database. This can usually be done via your web hosting control panel (such as cPanel) or directly in phpMyAdmin.
- Open phpMyAdmin: Log in to your cPanel or hosting dashboard and navigate to phpMyAdmin.
- Select database: On the left side of the phpMyAdmin dashboard, select the database that contains your WordPress website. If you are unsure which database it is, check the file.
wp-config.phpin your WordPress installation directory to find out the name of the database. - Execute SQL command: After selecting the correct database, click the "SQL" or "Execute SQL" tab to manually enter an SQL statement. You should now see a field where you can enter your SQL code. Paste the following SQL code:
sql
-
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');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='product');
DELETE FROM wp_posts WHERE post_type = 'product';This code will delete all products and their associated metadata and taxonomy relationships. Note that your table prefixes may be different; the default prefix is "wp_", but if you specified something else during installation, you should change it. Wordpress If you have set the parameters, you will need to adjust the code accordingly.
- Check changes: After executing the SQL command, all products should be removed from WooCommerce. You can log in to your WordPress dashboard and go to WooCommerce to see if the products have been deleted.
Keep in mind that this process cannot be undone once you've deleted the products. If something goes wrong, you may need to restore your database from a backup you hopefully created beforehand. Always be careful when making direct changes to your database, as this can have serious consequences for your website.








Be the first to leave a comment!