Magento 2 – Set Customer Subscribed to Newsletter by Customer ID

customermagento2newsletter

I have an existing customer id, i want to set the customer subscribed to the newsletter using this customer id, is there a way to do this?

Best Answer

Notes: This answer may need to be changed in later version of Magento when service contract is implemented for the newsletter module. For now we will have to make do with using model method.

use Magento\Newsletter\Model\SubscriberFactory; // Inject SubscriberFactory
...
$subscriber = $this->subscriberFactory->create();
$subscriber->subscribeCustomerById($customerID);

Hope this helps.

Related Topic