---
title: "How to "Add to Wishlist" Without Redirecting to Wishlist Page in Magento 2?"
url: "https://magecomp.com/blog/add-to-wishlist-without-redirecting-to-wishlist-page-in-magento-2/"
date: "2021-02-12T18:49:31+00:00"
modified: "2025-02-20T08:55:23+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 638
reading_time: "4 min read"
summary: "Hello Magento Friends,"
description: "Redirecting customers to the wishlist page results in interruption of their shopping journey. Learn How to "Add to Wishlist" Without Redirecting to Wishlist ..."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "10 Best Magento 2 WhatsApp Contact Extension Providers You Can Trust"
    url: "https://magecomp.com/blog/best-magento-2-whatsapp-contact-extension-providers/"
  - title: "How to Programmatically Delete Directory in Magento 2?"
    url: "https://magecomp.com/blog/programmatically-delete-directory-magento-2/"
  - title: "How to Show List of All Categories with Links at Sidebar on Category Page in Magento 2"
    url: "https://magecomp.com/blog/show-list-categories-links-sidebar-category-page-magento-2/"
---

# How to "Add to Wishlist" Without Redirecting to Wishlist Page in Magento 2?

_Published: February 12, 2021_  
_Author: Dhiren Vasoya_  

![How to add product to wishlist without redirecting to wishlist page in magento2](https://magecomp.com/blog/wp-content/uploads/2021/02/How-to-add-product-to-wishlist-without-redirecting-to-wishlist-page-in-magento2-1024x512.webp)

**Hello Magento Friends,**

Welcome again to Magento How to blog series by MageComp. Today I will justify **How to “Add to Wishlist” Without Redirecting to Wishlist Page in Magento 2**.
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-3.webp)](https://magecomp.com/services/magento-upgrade-services/)

The primary goal of every E-commerce store is to enhance customer satisfaction. Providing customers the option to add their wished products to the wishlist, makes their future purchases more easily. For that, you need to [**configure the wishlist in Magento 2**](https://magecomp.com/blog/configure-wishlist-in-magento-2/).
When the customer adds the item to the wishlist, the customer gets redirected to the wishlist page in default Magento. This interrupts the shopping journey of customers and the customer may not even come back to surf other products.
To avoid this, you can eliminate wishlist page redirection when the customer clicks on “Add to Wishlist”. So let’s look at the steps on How to “Add to Wishlist” Without Redirecting to Wishlist Page in Magento 2.
## Steps to “Add to Wishlist” Without Redirecting to Wishlist Page in Magento 2:
**Step 1:** First you need to go to the below path
**app\code\Vendor\Extension\etc\di.xml**

And add the below code
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="MagentoWishlistControllerIndexAdd" type="VendorExtensionControllerIndexAdd" />
</config>
```

**Step 2:** Next, navigate to the below path
**app\code\Vendor\Extension\Controller\Index\Add.php**

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

namespace VendorExtensionControllerIndex;

use MagentoCatalogApiProductRepositoryInterface;
use MagentoFrameworkAppAction;
use MagentoFrameworkDataFormFormKeyValidator;
use MagentoFrameworkExceptionNotFoundException;
use MagentoFrameworkExceptionNoSuchEntityException;
use MagentoFrameworkControllerResultFactory;

class Add extends MagentoWishlistControllerIndexAdd
{
    public function execute()
    {
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        if (!$this->formKeyValidator->validate($this->getRequest()))
        {
            return $resultRedirect->setPath('*/');
        }

        $wishlist = $this->wishlistProvider->getWishlist();
        if (!$wishlist)
        {
            throw new NotFoundException(__('Page not found.'));
        }

        $customer_session = $this->_customerSession;

        $reqparams = $this->getRequest()->getParams();

        if ($customer_session->getBeforeWishlistRequest())
        {
            $reqparams = $customer_session->getBeforeWishlistRequest();
            $customer_session->unsBeforeWishlistRequest();
        }

        $product_id = isset($reqparams['product']) ? (int)$reqparams['product'] : null;
        if (!$product_id)
        {
            $resultRedirect->setPath('*/');
            return $resultRedirect;
        }

        try
        {
            $product = $this->productRepository->getById($product_id);
        }
        catch (NoSuchEntityException $e)
        {
            $product = null;
        }

        if (!$product || !$product->isVisibleInCatalog())
        {
            $this->messageManager->addErrorMessage(__('We can't specify a product.'));
            $resultRedirect->setPath('*/');
            return $resultRedirect;
        }

        try
        {
            $buyRequest = new MagentoFrameworkDataObject($reqparams);

            $result = $wishlist->addNewItem($product, $buyRequest);
            if (is_string($result))
            {
                throw new MagentoFrameworkExceptionLocalizedException(__($result));
            }
            if ($wishlist->isObjectNew())
            {
                $wishlist->save();
            }
            $this->_eventManager->dispatch(
                'wishlist_add_product',
                ['wishlist' => $wishlist, 'product' => $product, 'item' => $result]
            );

            $referer = $customer_session->getBeforeWishlistUrl();
            if ($referer)
            {
                $customer_session->setBeforeWishlistUrl(null);
            }
            else
            {
                $referer = $this->_redirect->getRefererUrl();
            }

            $this->_objectManager->get(MagentoWishlistHelperData::class)->calculate();

            $this->messageManager->addComplexSuccessMessage(
                'addProductSuccessMessage',
                [
                    'product_name' => $product->getName(),
                    'referer' => $referer
                ]
            );
        }
        catch (MagentoFrameworkExceptionLocalizedException $e)
        {
            $this->messageManager->addErrorMessage(
                __('We can't add the item to Wish List: %1.', $e->getMessage())
            );
        }
        catch (Exception $e)
        {
            $this->messageManager->addExceptionMessage(
                $e,
                __('We can't add the item to Wish List.')
            );
        }

        $resultRedirect->setUrl($this->_redirect->getRefererUrl());
        return $resultRedirect;
    }
}
```

## [![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-4.webp)](https://magecomp.com/magento-malware-removal.html)

## Conclusion:
Hopefully, now you can easily allow customers to “Add to Wishlist” Without Redirecting to Wishlist Page in Magento 2. In case you face difficulties while performing the above steps, just mention them in the comment part and I will get back to you. Do spread the article amongst your Magento colleagues and through social media. Stay in touch with us so that you do not miss out on useful solutions for your Magento 2 store.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2023/10/Magento-2-Speed-Performance-Optimization-Services-CTA-4.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/add-to-wishlist-without-redirecting-to-wishlist-page-in-magento-2/](https://magecomp.com/blog/add-to-wishlist-without-redirecting-to-wishlist-page-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-29 12:35:33 UTC_  
