We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Use Factory,
    MagentoNewsletterModelSubscriberFactory

    Using isSubscribed() method. You can check the user is a subscriber to the newsletter or not.

    <?php
    namespace MagemonkeySubscriberModel;
    
    use MagentoFrameworkExceptionLocalizedException;
    use MagentoNewsletterModelSubscriberFactory;
    
    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;
        }
    }

     

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote