How to check if customer is already subscribed to newsletter
Alternatively you can try this, if you have the customer's email address:
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
if ($subscriber->getId()) {
// put your logic here...
}
Or if you have customer ID then you can directly check in newsletter_subscriber
table to check if customer ID exists or not.
You have to check also the subscription status:
if(Mage::getSingleton('customer/session')->isLoggedIn()){
$email = Mage::getSingleton('customer/session')->getCustomer()->getData('email');
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
if($subscriber->getId())
{
$isSubscribed = $subscriber->getData('subscriber_status') == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
}
}
In my opinion none of the above answers are very convenient in that they either don't check if the customer is actually subscribed or don't handle the case where a subscription has not been found, so here goes:
$customerIsSubscribed = false;
$customer = Mage::getSingleton('customer/session')->getCustomer();
if ($customer) {
$customerEmail = $customer->getEmail();
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customerEmail);
if ($subscriber) {
$customerIsSubscribed = $subscriber->isSubscribed();
}
}