---
title: "How to Prevent Adding Duplicate Product to Wishlist in Magento 2"
url: "https://magecomp.com/blog/prevent-adding-duplicate-product-to-wishlist-in-magento-2/"
date: "2021-03-12T14:45:15+00:00"
modified: "2025-02-20T09:41:02+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 361
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Prevent adding duplicate products to the wishlist for ease of access. Learn How to Prevent Adding Duplicate Product to Wishlist in Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2: How to Add Custom Field in Newsletter Subscription"
    url: "https://magecomp.com/blog/magento-2-add-custom-field-in-newsletter-subscription/"
  - title: "How to Add Block After Add to Cart Button in Magento 2 Product page?"
    url: "https://magecomp.com/blog/add-block-add-cart-button-magento-2-product-page/"
  - title: "How to Install Google reCAPTCHA on Magento custom form"
    url: "https://magecomp.com/blog/install-google-recaptcha-magento-custom-form/"
---

# How to Prevent Adding Duplicate Product to Wishlist in Magento 2

_Published: March 12, 2021_  
_Author: Dhiren Vasoya_  

![How to prevent adding duplicate product to wishlist in Magento 2](https://magecomp.com/blog/wp-content/uploads/2021/03/How-to-prevent-adding-duplicate-product-to-wishlist-in-Magento2-1024x512.webp)

**Hello Magento Friends,**

Hope everything is groovy and fab at your end. Today I will help you to solve How to Prevent Adding Duplicate Product to Wishlist in Magento 2.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-3.webp)](https://magecomp.com/magento-performance-optimization.html)

In default Magento 2, if the customer adds any product to the wishlist it also allows repetitive products to be added to the wishlist. The Magento 2 store admin can still delete the duplicate products in the wishlist and also prevent adding the same. The customers can easily manage their wishlist by preventing duplicate items to be added.
So, let’s get started with the steps on How to Prevent Adding Duplicate Product to Wishlist in Magento 2.
## Steps to Prevent Adding Duplicate Product to Wishlist in Magento 2:
**Step 1:** Firstly, go to the below path
**app\code\Vendor\Extension\etc\events.xml**

Now, add the below code
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch_wishlist_index_add">
        <observer name="wishlist_index_add_before" instance="VendorExtensionObserverWishlistItemBeforeAdd" />
    </event>
</config>
```

**Step 2:** Next, move to the below path
**app\code\Vendor\Extension\Observer\WishlistItemBeforeAdd.php**

And add the code as mentioned below
```
<?php

namespace VendorExtensionObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkExceptionLocalizedException;

class WishlistItemBeforeAdd implements ObserverInterface
{
    protected $customerSession;

    protected $wishlist;

    public function __construct(
        MagentoCustomerModelSession $customerSession,
        MagentoWishlistModelWishlist $wishlist)
    {
        $this->customerSession = $customerSession;
        $this->wishlist = $wishlist;
    }

    public function execute(MagentoFrameworkEventObserver $observer)
    {

        $customer_id = $this->customerSession->getCustomer()->getId();
        $currentProduct_id = $observer->getRequest()->getParam('product');

        if($customer_id)
        {
            $currentCustomerWishlist = $this->wishlist->loadByCustomerId($customer_id);
            $wishlistItems = $currentCustomerWishlist->getItemCollection();

            foreach ($wishlistItems as $wishlistItem)
            {
                if ($wishlistItem->getProductId() == $currentProduct_id)
                {
                    $wishlistItem->delete();
                }
            }
        }
        return $observer;
   }
}
```

## [![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-3.webp)](https://magecomp.com/services/hyva-theme-development/)

## Conclusion:
Hopefully, all are able to Prevent Adding Duplicate Product to Wishlist in Magento 2. For any difficulty, while executing the code, do let me know in the comment sections below. Ensure you share the article with your Magento colleagues and on your social media platforms.
Stay in touch for future updates!
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-3.webp)](https://magecomp.com/services/hire-magento-programmer/)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/prevent-adding-duplicate-product-to-wishlist-in-magento-2/](https://magecomp.com/blog/prevent-adding-duplicate-product-to-wishlist-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-24 19:35:12 UTC_  
