WooCommerce tool: SQL snippets

Wanneer je alle tags of categorieen uit je WooCommerce installatie wilt verwijderen, dan kan de reguliere weg via de WordPress backend enorm veel tijd in beslag nemen. Met onderstaande SQL queries verwijder je de inhoud in enkele seconden. Vele malen sneller :)

Log in op je PHPMyAdmin, selecteer de betreffende database, en klik vervolgens op SQL. 

Daar plaats je een van onderstaande scripts, en klik je vervolgens op 'Go' om het uit te voeren.

Script verwijderen van product tags

DELETE a,c FROM wp_terms AS a 
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'product_tag';
	

Script verwijderen van product categorie├źn

DELETE a,c FROM wp_terms AS a 
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id 
LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id 
WHERE c.taxonomy = 'product_cat';

Script verwijderen van ALLE producten

-- Remove all attributes from WooCommerce
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%');
DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%';
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);

-- Delete all WooCommerce products
DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wp_posts WHERE post_type IN ('product','product_variation');

-- Delete orphaned postmeta
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL
		

Nog steeds hulp nodig? Contact ons Contact ons