I have created a module to add custom fee value. I want to show this custom fee in all pages(frontend:order view page, print page etc, backend:order view page, sales invoice pdf, emails)

I have shown it all pages except for admin side invoice pdf. How can I do that? Which XML do I need to edit?

I have tried editing the layout in adminhtml sales_order_invoice_new.xml, sales_order_invoice_updateqty.xml, sales_order_invoice_view.xml

Please help...

  • You should accept an answer to help other developers to find their right solution. – Prince Patel Mar 27 '18 at 8:36
  • how to display in order view page? – Sagar Parikh SGR Jan 7 at 6:50

To display custom applied fee on Invoice Page you need to create there layout files

  1. sales_order_invoice_new.xml
  2. sales_order_invoice_updateqty.xml
  3. sales_order_invoice_view.xml

Here I made a full module to display custom fee to order, invoice, credit memo with admin configuration you can take a reference or use this module: https://github.com/mageprince/magento2-extrafee/

Here I give one file example:


<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="invoice_totals">
            <block class="Prince\Extrafee\Block\Adminhtml\Sales\Order\Invoice\Totals"



namespace Prince\Extrafee\Block\Adminhtml\Sales\Order\Invoice;

class Totals extends \Magento\Framework\View\Element\Template
     * @var \Prince\Extrafee\Helper\Data
    protected $_helper;
     * @var \Magento\Sales\Model\Order\Invoice
    protected $_invoice = null;
     * @var \Magento\Framework\DataObject
    protected $_source;
     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Prince\Extrafee\Helper\Data $helper
     * @param array $data
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Prince\Extrafee\Helper\Data $helper,
        array $data = []
    ) {
        $this->_helper = $helper;
        parent::__construct($context, $data);
    public function getSource()
        return $this->getParentBlock()->getSource();
    public function getInvoice()
        return $this->getParentBlock()->getInvoice();
    public function initTotals()
        if(!$this->getSource()->getFee()) {
            return $this;
        $total = new \Magento\Framework\DataObject(
                'code' => 'fee',
                'value' => $this->getSource()->getFee(),
                'label' => $this->_helper->getTitle(),
        $this->getParentBlock()->addTotalBefore($total, 'grand_total');
        return $this;
| improve this answer | |

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.