Question

I've been trying to remove subtotal from the invoice pdf.

I have override vendor/magento/module-sales/etc/pdf.xml from my custom module but didn't work. I have just commented on the subtoal. but it not working.

Does anyone have an idea how to do it in a perfect and standard way?

Was it helpful?

Solution

I think the best approach is to overwrite the view/frontend/layout/sales_order_printinvoice.xml layout file in your custom theme and change the line:

<block class="Magento\Sales\Block\Order\Invoice\Totals" name="invoice_totals" template="Magento_Sales::order/totals.phtml" cacheable="false">

so that it uses a custom block class, then create this custom block class in your module and make it inherit the Magento\Sales\Block\Order\Invoice\Totals class, then override the _initTotals() method like this:

protected function _initTotals()
{
    parent::_initTotals();
    $this->removeTotal('subtotal');
    return $this;
}

You probably already saw that the totals used in invoice pdf are used in other invoice related functionalities and that they are registered programmatically on the PHP side. My suggestion described above is to leave the other functionalities untouched while adding your customization only in the area of interest (so no preference, plugin or manual validations in the phtmls).

Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top