In WooCommerce stores, it's common to accidentally upload the same product multiple times — especially with the same SKU (Stock Keeping Unit). This not only creates confusion but can negatively impact your SEO and the shopping experience.
In this guide, you'll learn how to automatically detect and delete duplicated products that share the same SKU — keeping only one copy of each.
Example scenario:
SKU: ABC-123
Two or more products exist with this same SKU.
You want to keep only one (preferably the newest), and delete the rest.
To handle this safely and efficiently, we’ll use the Code Snippets plugin to run a custom script that automatically deletes duplicate products with the same SKU.
Go to your WordPress dashboard.
Navigate to Plugins > Add New.
Search for “Code Snippets”.
Install and activate the plugin by Code Snippets.
In your WordPress dashboard, go to Snippets > Add New.
Give it a title like Duplicate SKU Cleaner
.
Paste the following code:
add_action('admin_init', 'delete_duplicate_sku_products_except_newest');
function delete_duplicate_sku_products_except_newest() {
if (!current_user_can('administrator')) {
return;
}
// Run only when manually triggered
if (isset($_GET['run_duplicate_cleaner'])) {
global $wpdb;
$results = $wpdb->get_results("
SELECT meta_value as sku, COUNT(*) as total
FROM {$wpdb->prefix}postmeta
WHERE meta_key = '_sku'
GROUP BY meta_value
HAVING total > 1
");
foreach ($results as $row) {
$sku = $row->sku;
$products = get_posts(array(
'post_type' => 'product',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC', // Keep the newest
'meta_query' => array(
array(
'key' => '_sku',
'value' => $sku
)
)
));
$keep = true;
foreach ($products as $product) {
if ($keep) {
$keep = false;
continue;
}
wp_delete_post($product->ID, true); // Permanently delete
}
}
wp_die('Duplicate products successfully cleaned. You can now deactivate this snippet.');
}
}
At the bottom of the snippet page, select:
"Only run in administration area"
Then click “Save and Activate”.
Open this URL in your browser (replace with your own domain):
https://yourdomain.com/wp-admin/?run_duplicate_cleaner=1
✅ This will scan your products for duplicate SKUs and automatically delete older duplicates, keeping only the most recent version of each.
Once completed, you’ll see the message:
“Duplicate products successfully cleaned.”
Go back to the Snippets page and deactivate or delete the snippet.
This ensures it won’t run again accidentally.
Doesn’t require editing your functions.php
.
Runs only for admin users inside the dashboard.
Executes only when you visit the special trigger URL.
Doesn’t slow down your site or cause crashes.
Always create a full backup before running bulk operations. (Try UpdraftPlus or Duplicator.)
If you have thousands of products, allow a few seconds for the process.
This method works for simple products — if you use variations, we can customize it further.
With this guide, you can finally say goodbye to duplicated WooCommerce products and clean up your product catalog with confidence. Your site will be leaner, faster, and more user-friendly.
Feel free to leave a comment or get in touch — I’m happy to help you further!