You can verify the customer is subscribed or not by the customer email id or Customer Id from the Newsletter Module.
Use Factory,
Magento\Newsletter\Model\SubscriberFactory
With isSubscribed() method you can check the Specific Customer is Subscriber to the newsletter.
<?php namespace Jesadiya\Subscriber\Model; use Magento\Framework\Exception\LocalizedException; use Magento\Newsletter\Model\SubscriberFactory; class IsSubscribed { /** * @var SubscriberFactory */ private $subscriberFactory; /** * @param SubscriberFactory $subscriberFactory */ public function __construct( SubscriberFactory $subscriberFactory ) { $this->subscriberFactory = $subscriberFactory; } /** * @param int $customerId * @return bool */ public function isCustomerSubscribeById($customerId) { $status = $this->subscriberFactory->create()->loadByCustomerId((int)$customerId)->isSubscribed(); return (bool)$status; } /** * @param string $email * @return bool */ public function isCustomerSubscribeByEmail($email) { $status = $this->subscriberFactory->create()->loadByEmail($email)->isSubscribed(); return (bool)$status; } }
The Result will be true or false based on the subscription status.
$customerId = 1; echo $this->isCustomerSubscribeById($customerId); $email = 'rakesh@rakeshjesadiya.com'; echo $this->isCustomerSubscribeByEmail($email);
Output:
Boolean (True/false)
You can know the customer subscription status by email or customer id in the simplest way.