1

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?

1 Answer 1

4
+50

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!

2
  • 1
    Thanks @diana-botean It's working. Commented Feb 17, 2021 at 9:01
  • glad I could help :) you are most welcome!
    – Diana
    Commented Feb 17, 2021 at 9:02

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.