So far I could add a custom fee to an order. It shows on checkout page, admin order view, admin invoice view, invoice pdf. But I don't know how I should do to display it in order/invoice email.

enter image description here

I see one way to do this is: override _initTotals method of Mage_Sales_Block_Order_Totals class. But I don't know if this will affect another places, or if other extension wants to do the same thing (adding some custom fees to the totals block), then they will conflict.

I doubted that there's a way to add a total to totals block via xml, or binding to some event...

Given the fact that there's a column called customfee_total in sales_flat_order table, what's the best way to achieve that?


I found the answer.

Add the following code to your module config.xml


add app/design/frontend/base/default/layout/customfee.xml

<?xml version="1.0"?>
        <reference name="order_totals">
            <block type="customfee/sales_totals_order_customfee" name="customfee"/>

        <reference name="invoice_totals">
            <block type="customfee/sales_totals_order_invoice_customfee" name="customfee"/>

        <reference name="creditmemo_totals">
            <block type="customfee/sales_totals_order_creditmemo_customfee" name="customfee"/>

Example app/code/local/Cream/CustomFee/Block/Sales/Totals/Order/Customfee.php

class Cream_CustomFee_Block_Sales_Totals_Order_Customfee extends Mage_Core_Block_Template {
  public function initTotals() {

    if((float) $this->getParentBlock()->getSource()->getCustomfeeTotal() == 0) {
      return $this;

    $total = new Varien_Object(array(
      'code'  => $this->getNameInLayout(),
      'value' => $this->getParentBlock()->getSource()->getCustomfeeTotal(),
      'label' => Mage::helper('customfee')->getName()

    $after = 'subtotal';

    $this->getParentBlock()->addTotal($total, $after);
    return $this;
| improve this answer | |
  • How solve it for Magento 2 ? – Jsparo30 Feb 13 '18 at 12:40

follow this tutorial

you have to override sales_order_invoice_totals




class Turnkeye_Insurance_Model_Total_Screen_Invoice extends Mage_Sales_Model_Order_Invoice_Total_Abstract
    public function collect(Mage_Sales_Model_Order_Invoice $invoice)
        $order = $invoice->getOrder();
        $amount = INSURANCE_FEE; //add your fee here
        if ($amount) {
            $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
            $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $amount);

        return $this;
| improve this answer | |
  • 2
    sorry but this is not the right answer, this only adds a row to invoice totals (admin order view), not the email – Thịnh Phạm Jan 15 '16 at 8:24
  • @ThịnhPhạm this is also add row in invoice total. – Qaisar Satti Jan 15 '16 at 9:33
  • @QaisarSatti could you pls help me @ magento.stackexchange.com/q/212197/57334 – zus Feb 6 '18 at 4:13

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.