Email Templates – How to Get Custom Variable into an Email Template

custom-variableemail-templatesorder-email

We currently use a plugin for gaining points when ordering items.

I want to display the users points balance inside various emails, now the plugin company gave me the code to echo out the current users balance however I am having a hard time figuring out where I can put this so that the variable will be available for me to use in my email templates.

$pointsBalance = Mage::getModel('rewards/customer')->load($customerId)->getUsablePoints();
echo $pointsBalance[1];

Can anyone advise me how I get a PHP variable like this in the right place so I can use it in my email templates like {{points.balance}}?

Best Answer

There's a simple way you can do this. Creating a custom variable for the email can be too much time consuming, so the easiest way to get this result would be using a .phtml file on your transnational email.

Add this to your email HTML:

{{block type='core/template' area='frontend' template='email/custom/mynote.phtml' order=$order}}

Create a file path/to/magento/app/design/frontend/base/default/template/email/custom/mynote.phtml

Now in this file you could do something like this:

   $pointsBalance = Mage::getModel('rewards/customer')->load($customerId)->getUsablePoints();
 echo $pointsBalance[1];

Done :)