I want to redirect User to Observer on Add to Wishlist Click

i want this for guest users

Example if customer is not logged in then it must redirect user same page

So far i have tried Following Events

 - wishlist_add_product
 - wishlist_add_item
 - wishlist_product_add_after

i am not Getting any solution

  • Add exact query what your requirement? You can use dispatch events. – Saurabh Dwivedi Aug 6 at 10:39
  • i want to dispatch event when a add to wishlist is pressed – Waqar Ali Aug 6 at 10:40
  • You can do it by ajax to dispatch event inside controller. – Saurabh Dwivedi Aug 6 at 10:46
  • For logged-in users it will work by default, here you mean the guest users? – Ejilarasan J Aug 6 at 10:52
  • yes i want for guest users – Waqar Ali Aug 6 at 10:53

You can use plugin for that instead of event and apply your code logic for redirection :


<?xml version="1.0"?>
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\Wishlist\Controller\Index\Plugin">
        <plugin name="guest_wishlist_plugin" type="RH\CustomPlugin\Plugin\GuestPlugin" sortOrder="10"/>



namespace RH\CustomPlugin\Plugin;

class GuestPlugin {

    public function beforeBeforeDispatch(\Magento\Wishlist\Controller\Index\Plugin $coreSubject, $subject, $request) {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/Rohan.log');
        $logger = new \Zend\Log\Logger();
        $logger->info('Your text message');
        //Apply your code logic
        return [$subject, $request];

  • not getting success :( – Waqar Ali Aug 6 at 11:09
  • please check my updated answer. – Rohan Hapani Aug 6 at 11:35
  • Now, It should be working :) Because, I tested this code. – Rohan Hapani Aug 6 at 11:43
  • 1
    Thank you its working fine – Waqar Ali Aug 6 at 11:51
  • Happy to help !! Happy coding :) – Rohan Hapani Aug 6 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.