Overriding Magento Sub Total and Adding New Row in Admin Invoice Email

Overriding Magento Sub Total and Adding New Row in Admin Invoice Email

September 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Overriding Magento Sub Total and Adding New Row in Admin Invoice Email

Overriding Magento Sub Total and Adding New Row in Admin Invoice Email

As an experienced developer, I understand your need to customize the invoice email sent from your Magento admin panel. One of the most common requirements is adding a new row after the sub-total line.

To achieve this, you’ll need to override the core Mage_Sales_Model_Order_Pdf_Invoices class that handles the generation of PDF invoices for the email. Here’s a step-by-step guide on how to do it:

Step 1: Create an extension

First, create a new Magento extension in your app/code/local directory. For this example, let’s name it MyCompany_YourExtension.

/var/www/magento/app/code/local/MyCompany/YourExtension/

Step 2: Override the core class

Create a new file named Order_Pdf_Invoices.php inside your extension’s model directory:

/var/www/magento/app/code/local/MyCompany/YourExtension/Model/Order/

The contents of this file should be:

class MyCompany_YourExtension_Model_Order_Pdf_Invoices extends Mage_Sales_Model_Order_Pdf_Invoices
{
    public function getPdf(array $invoices = array())
    {
        // Your custom logic here to add a new row after sub-total

        return parent::getPdf($invoices);
    }
}

Step 3: Update the config.xml file

Now, open your extension’s config.xml file located in:

/var/www/magento/app/code/local/MyCompany/YourExtension/etc/

Add the following XML to configure your model override:

<models>
    <yourextension>
        <class>MyCompany_YourExtension_Model</class>
    </yourextension>
    <sales>
        <rewrite>
            <order_pdf_invoices>MyCompany_YourExtension_Model_Order_Pdf_Invoices</order_pdf_invoices>
        </rewrite>
    </sales>
</models>

Step 4: Add your new row

In the getPdf() function of your Order_Pdf_Invoices.php file, you can now add your custom logic to insert a new row after the sub-total. This could be a simple line item or any other data you want to include.

Here’s an example of adding a basic ‘Discount’ row:

public function getPdf(array $invoices = array())
{
    // Fetch all PDF invoices
    $pdfInvoices = parent::getPdf($invoices);

    // Get the first page and add your new row after sub-total
    foreach ($pdfInvoices as $invoice) {
        if ($invoice->getPage(0)) {
            $invoice->setPage(0, $this->_table->getRowAfterSubTotal());
        }
    }

    return $pdfInvoices;
}

Step 5: Flush the cache

Finally, flush your Magento cache to apply the changes:

/var/www/magento/shell/installdb.php --action=cacheFlush

Remember that modifying core files directly is generally discouraged in favor of using extensions and overrides. Always try to keep your customizations separate from the core for easier upgrades.

For more detailed guides on Magento development and customization, I recommend checking out Laravel Company’s comprehensive list of resources.

Conclusion

By following these steps and understanding how Magento’s PDF invoice generation works, you can successfully add a new row after the sub-total line in your admin invoice emails. Always test changes thoroughly to ensure they don’t introduce any unexpected behaviors.

Remember that Magento’s core files are complex and changing them requires careful consideration of potential impacts on other areas of the system. If you’re unsure about anything, always consult the official Magento documentation or seek assistance from a qualified developer.

Happy coding!

Extensions Admin Configuration Email

Our network