Solved: Magento Newsletter Unsubscribe Link Not Working
Sending a newsletter is imperative for any e-commerce brand to improve its brand awareness and keep your shoppers engaged to your store.
Here the email service provider expects you, as the sender of emails, to include an unsubscribe or unsubscription link in your email to keep the user’s experience intact. And give the users the convenience of easily opting out of your email list if they are not interested.
At times, as a Magento 2 store owner, the hurdle of your Magento Newsletter Unsubscribe Link Not Working can get hectic and can also leave your shoppers frustrated. In this blog, I will explain how to create a custom module to add newsletter unsubscribe link and pass it easily.
Solution: Magento Newsletter Unsubscribe Link Not Working
In order to implement the unsubscription link, here will you have to override two core classes in Magento:
By extending these two classes, you will be able to make the necessary changes in your newsletter.
Let us take a look at each class closely.
Template.php
In the Template.php file, extend the MagentoNewsletterModelTemplate class.
In this method, add the unsubscription link by setting the template text and add the variable {{var subscriber.unsubscriptionLink}}.
1 2 3 4 5 6 7 8 9 10 |
if (!$this->getData('template_text') && !$this->getId()) { $this->setData( 'template_text', __( 'Follow this link to unsubscribe <!-- This tag is for unsubscribe link -->' . '{{var subscriber.unsubscriptionLink}}' . '' ) ); } |
This variable ensures that each email has a unique unsubscription link for each email you send to your subscribers.
Now moving to the next step.
Queue.php
In the Queue.php file method, you will have to extend the MagentoNewsletterModelQueue class. In this method, you will be adding the link to your email template.
1 |
$item->setData('unsubscriptionLink', $item->getUnsubscriptionLink()); |
This code ensures that the link gets included in every email you send and that it works effectively.
& that’s it! 🎉
This way, you can send a newsletter with an unsubscription link to avoid unexpected errors when a shopper tries to opt-out. I hope this solution helps you solve this issue. I encourage you to try it yourself and if you face any issues while implementing the solution. Let me know in the comment section. I would be happy to help you.
And if liked this Magento newsletter unsubscribe link not working solution, consider sharing it on your social media and with any Magento community you might be a part of.
Thank you for reading!
✨ Here is our handpick list of Magento 2 blogs which you might like: ✨
- How to Manage Newsletter Subscriptions in Magento 2
- How to Enable Ajax Newsletter in Magento 2
- How to Add Newsletter Subscription Column to Customer Grid in Magento 2
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How to Add a WhatsApp Share Button to Shopify?
15 SEO Chrome Extensions You Should Use in 2024
Next