0

Is there a variable I can include in the transactional emails to show whether the customer has subscribed to the Newsletter or not?

1

In app\code\core\Mage\Sales\Model\Order.php there is a function sendNewOrderEmail() you can see this code:

$mailer->setTemplateParams(array(
                'order'        => $this,
                'billing'      => $this->getBillingAddress(),
                'payment_html' => $paymentBlockHtml
            )
        );

in same function you can check if customer is subscribed to newsletter or not like using this code:

$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($this->getCustomerEmail());
if ($subscriber->getId()) {
     $is_subscribed=true;
}
else{
$is_subscribed=false;
}

then you can pass this variable in in setTemplateParams like:

$mailer->setTemplateParams(array(
                'order'        => $this,
                'billing'      => $this->getBillingAddress(),
                'payment_html' => $paymentBlockHtml,
                'is_subscribed' = > $is_subscribed
            ));

then in email template you can check like this

{{if is_subscribed}}

Note: override this function instead of making changes in core code

0

You can check customer by email if the email is already in subscribe list

$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.

  • But I can't do this within a transactional email template I guess – Shakamal Feb 15 '18 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.