This snippet will delete orphaned WooCommerce product variations from the database. These are product variations that the main product was deleted.
<?php
// Please make a backup of your database before running this snippet
// This snippet should only be ran in "Manual" mode.
global $wpdb;
$deleted_variations = $wpdb->get_rows("DELETE o FROM {$wpdb->posts} o LEFT OUTER JOIN {$wpdb->posts} r ON o.post_parent = r.ID WHERE r.id IS null AND o.post_type = 'product_variation'");
echo "There are $deleted_variations variations on your site.";