[SQL] Recount product on WooCommerce product categories

In some case, you delete products on categories but the couting for that category not updated.

I checked the database and release this SQL command to help you solve that issue.

 

Run this commands in PhpMySQL to solve issues.

-- clean relation terms
DELETE rel
FROM wp_term_relationships rel
LEFT JOIN wp_posts p ON rel.object_id = p.ID
WHERE p.ID IS NULL;

-- Update count product_cat
UPDATE wp_term_taxonomy tt SET count = (SELECT COUNT(object_id) FROM wp_term_relationships WHERE term_taxonomy_id = tt.term_taxonomy_id) WHERE taxonomy = 'product_cat';

Leave a Reply

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