Wednesday, July 2, 2025

SQL to delete all WooCommerce products except those with "draft" status

 -- Disable foreign key checks (important for InnoDB)

SET

    FOREIGN_KEY_CHECKS = 0;

    -- Delete product meta

DELETE

    pm

FROM

    wp_postmeta pm

JOIN wp_posts p ON

    pm.post_id = p.ID

WHERE

    p.post_type = 'product' AND p.post_status != 'draft';

    -- Delete term relationships

DELETE

    tr

FROM

    wp_term_relationships tr

JOIN wp_posts p ON

    tr.object_id = p.ID

WHERE

    p.post_type = 'product' AND p.post_status != 'draft';

    -- Delete the products

DELETE

FROM

    wp_posts

WHERE

    post_type = 'product' AND post_status != 'draft';

    -- Enable foreign key checks again

SET

    FOREIGN_KEY_CHECKS = 1;

Replace old IP with New one in Direct Admin

./ipswap.sh Old_IP  New_IP for example:  ./ipswap.sh 35.224.2.88 104.197.113.37