Actionable Steps to Remove SKU Column From Magento 2 Invoice PDF
Earlier I posted the solution to remove SKU from product page in Magento 2.
And we know that SKUs are something that the customers need not handle. The customers want to enjoy the shopping and leave handling the technical aspects on the developers!
However, SKUs are important in Magento 2 for unique identification of the products and hence it has a place in the product page, invoice and invoice pdf!
But we know that customers can live without knowing the SKU of the products they purchased 😛
Hence, we’ll remove SKU column from Magento 2 invoice pdf! And that too programmatically so as to quickly finish this task!
Method to remove SKU column from Magento 2 Invoice PDF:
Visit How to Override a Method of Abstract File of Magento 2 Invoice PDF
Remove the below lines from this solution’s override class MagentoSalesModelOrderPdfInvoice
1 |
$lines[0][] = ['text' => __('SKU'), 'feed' => 290, 'align' => 'right']; |
and also remove following code from MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
1 2 3 4 5 6 |
$lines[0][] = [ // phpcs:ignore Magento2.Functions.DiscouragedFunction 'text' => $this->string->split(html_entity_decode($this->getSku($item)), 17), 'feed' => 290, 'align' => 'right', ]; |
For downloadable product, go to MagentoDownloadableModelSalesOrderPdfItemsInvoice and comment or remove the below code:
1 2 3 4 5 6 |
// draw SKU $lines[0][] = [ 'text' => $this->string->split($this->getSku($item), 17), 'feed' => 290, 'align' => 'right', ]; |
1 2 3 4 5 6 7 8 9 |
// draw SKUs if (!$childItem->getOrderItem()->getParentItem()) { $text = []; foreach ($this->string->split($item->getSku(), 17) as $part) { $text[] = $part; } $line[] = ['text' => $text, 'feed' => 255]; } |
However, if you do not want to make any changes in the default file, you can override it by installing this extension.
That’s it.
Making customers’ life easier is our job and the post helps for the same!
And my task is to solve the readers’ doubts. So please mention them, if any, in the Comments section below and I’d be there for you 🙂
I’d be grateful if you take time out to share the solution with fellow developers via social media.
Thanks.
Facing issues with your Magento store or want to add new features? Our Magento Development Services are here to help!
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How To Add Button Next To Add To Cart Button In Magento 2
How To Remove “Add To Wishlist” button in Magento 2
Next