Magento – Magento2 : Remove shipping charge and credit cart type and number from order invoice

abstract classinvoice-pdfmagento2orders

I want to remove shipping charge and credit card type and credit card number from order invoice.

Blockquote

please check image:

I have overridden this core file

vendor/magento/module-sales/Model/Order/Pdf/Invoice.php
this file working fine.

But while overridding this file

vendor/magento/module-sales/Model/Order/Pdf/AbstractPdf.php

I am not able to get any update of this file. I have commented some code from this file but not got any change.

Best Answer

Try creating same methods which you want to override from AbstractPdf.php in your overided Invoice.php file. For example:

1) Create a preference for Invoice.php in di.xml

<preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="Vendor\Module\Model\Order\Pdf\Invoice" />

2) In Vendor\Module\Model\Order\Pdf\Invoice, in you case create a method insertOrder

/**
 * Insert order to pdf page
 *
 * @param \Zend_Pdf_Page &$page
 * @param \Magento\Sales\Model\Order $obj
 * @param bool $putOrderId
 * @return void
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
 * @SuppressWarnings(PHPMD.NPathComplexity)
 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
 */
protected function insertOrder(&$page, $obj, $putOrderId = true)
{
    // comment relevent code according to your requirement
}
Related Topic