Awais Khan
Awais Khan

Reputation: 175

Show error message in guest subscriber if user already subscribe with that email

I want to show a custom message if user already subscribed with a email address. like

You are already subscribed. Thank you.

Instead of this message.

enter image description here

I am using magento2.1.8.

Upvotes: 0

Views: 1119

Answers (2)

Indranil Maity
Indranil Maity

Reputation: 101

You need to modify this simple checking.

Try this -

Go to this path if you haven't override NewAction.php file yet vendor\magento\module-newsletter\Controller\Subscriber and open NewAction.php file.

Replace this code:

if ($subscriber->getId() && $subscriber->getSubscriberStatus() == \Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED)

With:

if($subscriber->getId())

That's all.

Upvotes: 0

Sharath Kumar
Sharath Kumar

Reputation: 216

You should define a preference (via di.xml) for the OOTB Controller that handles the Subscription sign-up process (Magento/Newsletter/Controller/Subscriber/NewAction.php) and in your custom controller's execute method - add the desired logic to check whether/not the customer has already subscribed and handle it accordingly.

Subscription Sign-up Code/Logic

Upvotes: 1

Related Questions