I want to provide more relevant information to the customer in the "New Order" email template dependent on what method of payment was selected when placing the order.

I implemented this method from ʍǝɥʇɐɯ here https://stackoverflow.com/a/6628433 and created /app/design/frontend/default/default/template/paymentstatus/orderemail.phtml

<?php if($this->getData('order')->getStatus()=='pending_payment_tt'): ?>
    <p style="font-size:12px; line-height:16px; margin:0;">
        <?php echo $this->__('Your Order Status is pending_payment_tt and you paid by Bank Transfer Payment') ?>
<?php elseif($this->getData('order')->getStatus()=='awaiting_check'): ?>
    <p style="font-size:12px; line-height:16px; margin:0;">
        <?php echo $this->__('Your Order Status is awaiting_check and you paid by Electronic Check') ?>
<?php else: ?>
    <p style="font-size:12px; line-height:16px; margin:0;">
        <?php echo $this->__('Your Order Status is pending and you probably paid by CC') ?>
<?php endif; ?>

then edited the New Order email template inserting

{{block type='core/template' area='frontend' template='paymentstatus/orderemail.phtml' order=$order}}

This all works well enough, however the actual content of the conditional message resides in a template file and I now want to pull the content from a Custom Variable enabling easier access to editing the message.

If I create a Custom Variable 'payment_comment', how should I insert it into my orderemail.phtml template?

I found this code but am not sure how to integrate it

$comment = Mage::getModel('core/variable')

3 Answers 3


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

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

  1. Static block new_order_email_standard will be used whenever a payment method specific block isn't found/active.
  2. Static block new_order_email_banktransfer will be used when the Bank Transfer payment method is selected.
  3. Static block new_order_email_checkmo will be used when the Check/Money
  4. You can continue creating as many different unique blocks as required.
  • Thank you for this solution. I have implemented the template file as is and created 4 new Static Blocks, one for each of the payment methods. Deployed for use in a multi website environment and it works perfectly.
    – webbuddy
    Sep 17, 2015 at 2:56
  • 1
    No problem. Glad that it worked for you! If you have a need for different blocks per website, that could be accomplished too.
    – Kane Shaw
    Sep 17, 2015 at 4:29

If you want to include custom data in an order email template you need to create a module that extends


Here you can create the data you want to include in the email i.e.

public function getCustomData(){
    return $_myData;

And in the order email template you can then access this data with

{{if order.getCustomData()}}
     <p><span class="no-link highlighted-text">{{var order.getCustomData()}}</span></p>

If you are looking Magento 2 solution then following post will help you.

Solution 1: use depend tag which check whether that variable has some value or not. You will need to add following code in your email template

{{depend shipping_company}}
               <h1>Your shipment is on its way.</h1>
             <img src="{{media url=wysiwyg/logo-dpd.png}}" alt="" />

Solution 2: Block technique for advance conditioning

{{block class='Magento\\Framework\\View\\Element\\Template' 
               area='frontend' template='Codedecorator_Learn::email/shipping_company.phtml' shipping_company=$shipping_company}}

Add above block code in your email template and create new phtml template in your plugin like following:

            if($block->getData('shipping_company') !='dpd') {
                    echo $block->getData('shipping_company'); 


for more detail you can visit following blog

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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