Does anyone know how to edit the following to have the name of the coupon as the label on the new order sales email instead of the coupon code?

<?php foreach ($this->getTotals() as $_code => $_total): ?>
    <?php if ($_total->getBlockName()): ?>
        <?php echo $this->getChildHtml($_total->getBlockName(), false); ?>
    <?php else:?>
    <tr class="<?php echo $_code?>">
            if ($_code=="discount") {
              $code_used = trim(str_replace(array("Discount (",")"),array(""),$this->escapeHtml($_total->getLabel())));
              $coupon = Mage::getModel('salesrule/coupon');
              $coupon->load($code_used, 'code');
              $rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
              $rule_name = $rule->getName();

         <td <?php echo $this->getLabelProperties()?>>
            <?php if ($_total->getStrong()):?>
            <strong><?php echo $this->escapeHtml($_total->getLabel());?></strong>
            <?php else:?>
            <?php echo $this->escapeHtml($_total->getLabel());?>
            <?php endif?>
        <td <?php echo $this->getValueProperties()?>>
            <?php if ($_total->getStrong()):?>
            <strong><?php echo $this->formatValue($_total) ?></strong>
            <?php else:?>
            <?php echo $this->formatValue($_total) ?>
            <?php endif?>
    <?php endif?>
<?php endforeach?>

1 Answer 1


Magento offers the possibility to add labels to your coupons. Check the 'Labels' tab while editing a discount rule. You can set a default value for the label (Default Rule Label for All Store Views) and/or separate labels for each store view.
That label is used everywhere the rule is used: in the cart totals, in the checkout totals, in the e-mail templates, in the order details view... I would use that one instead of trying to display the name of the rule.

This feature is available starting Magento CE1.4/ EE1.9 (I think). If you are using that version or something higher it should be available.

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.