Easy method to add conditional text into a transactional email template but still be able to edit the content in the backend.
This example will allow you to use different text in an email depending on the Payment Method used when the order was placed. You can adapt the logic to suit your needs if it's not the payment method that you want to check.
In your transactional email template add in the following line where you want your conditional text to appear.
{{block type='core/template' area='frontend' template='myemail/orderemail.phtml' order=$order}}
Create a PHTML (php) file at /app/design/frontend/base/default/template/myemail/orderemail.phtml
<?php
$order = $this->getData('order');
if(is_object($order)) {
$payment_method_code = $order->getPayment()->getMethodInstance()->getCode();
} else {
$payment_method_code = "standard";
}
$checkUniqueBlock = Mage::getModel('cms/block')->load('new_order_email_'.$payment_method_code)->getIsActive();
$checkStandardBlock = Mage::getModel('cms/block')->load('new_order_email_standard')->getIsActive();
$block = false;
if($checkUniqueBlock) {
$block = $this->getLayout()->createBlock('cms/block')->setBlockId('new_order_email_'.$payment_method_code);
} elseif($checkStandardBlock) {
$block = $this->getLayout()->createBlock('cms/block')->setBlockId('new_order_email_standard');
}
if($block) {
echo $block->toHtml();
}
With this code in the PHTML file, you can now create static blocks via the Magento backend that will be used depending on the payment method selected!
- Static block
new_order_email_standard
will be used whenever a payment method specific block isn't found/active. - Static block
new_order_email_banktransfer
will be used when the Bank Transfer payment method is selected. - Static block
new_order_email_checkmo
will be used when the Check/Money - You can continue creating as many different unique blocks as required.