X
X
X
X

How to Delete Duplicate Products in Your WordPress Site?

HomepageArticlesE-TicaretHow to Delete Duplicate Products in...

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.

The Problem: Duplicate Products with Same SKU

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.

The Solution: Use Code Snippets for Safe Automation

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.

Install the Code Snippets Plugin

  1. Go to your WordPress dashboard.

  2. Navigate to Plugins > Add New.

  3. Search for “Code Snippets”.

  4. Install and activate the plugin by Code Snippets.

Add a New Code Snippet

  1. In your WordPress dashboard, go to Snippets > Add New.

  2. Give it a title like Duplicate SKU Cleaner.

  3. 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.');
}
}

Configure the Snippet Settings

  • At the bottom of the snippet page, select:
    "Only run in administration area"

  • Then click “Save and Activate”.

Run the Script (One-Time Trigger)

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.

What to Do After Cleanup

  • 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.

Why This Method Is Safe

  • 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.

Pro Tips

  • 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.

Conclusion

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.

Got Questions?

Feel free to leave a comment or get in touch — I’m happy to help you further!


Top