{"id":2289,"date":"2023-09-20T07:30:22","date_gmt":"2023-09-20T07:30:22","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/display-extra-fee-to-the-total-of-order-invoice-pdf-in-magento-2\/"},"modified":"2025-05-21T16:45:54","modified_gmt":"2025-05-21T11:15:54","slug":"display-extra-fee-to-the-total-of-order-invoice-pdf-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/display-extra-fee-to-the-total-of-order-invoice-pdf-in-magento-2\/","title":{"rendered":"Display Extra Fee to The Total of Order Invoice PDF In Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A detailed invoice is essential to enhance your customers\u2019 shopping experience for them to understand the pricing breakdown of the product completely.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, if there are any extra charges on delivery or the shoppers have opted for an EMI option. All information must display in your invoice with a proper breakdown.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the shopper opts for an EMI option, they should know the amount they have paid with the balance they must pay in the future.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It might be a limiting factor for you as a Magento 2 store owner as the default&nbsp;<a href=\"https:\/\/business.adobe.com\/in\/products\/magento\/magento-commerce.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2<\/a>&nbsp;doesn\u2019t offer any built-in feature to show extra fees in order invoices.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this blog, overcome this limitation and learn how to seamlessly&nbsp;<em><strong>Display Extra Fee to The Total Order Invoice PDF in Magento 2.<\/strong><\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Display Extra Fee to The Total of Order Invoice Pdf In Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here let us take an example of EMI payments. Here if your shopper has made a payment, so here is a breakdown of how you can showcase the entire detail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 1:&nbsp;<\/strong>Create your pdf.xml file in the Vendor\/Module\/etc folder.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This code calculates the amount paying now and the remaining amount using the model and displays even if the value is zero.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Create pdf.xml In Vendor\/Module\/etc Folder\n\n&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Sales:etc\/pdf_file.xsd\">\n    &lt;totals>\n        &lt;total name=\"pay_now_invk\">\n            &lt;title translate=\"true\">Amount Paying Now&lt;\/title>\n            &lt;source_field>partial_pay_now&lt;\/source_field>\n            &lt;font_size>7&lt;\/font_size>\n            &lt;display_zero>true&lt;\/display_zero>\n            &lt;model>Vendor\\Module\\Model\\Sales\\Pdf\\PayNow&lt;\/model>\n            &lt;sort_order>350&lt;\/sort_order>\n        &lt;\/total>\n        &lt;total name=\"pay_later_invk\">\n            &lt;title translate=\"true\">Remaining Amount&lt;\/title>\n            &lt;source_field>partial_pay_later&lt;\/source_field>\n            &lt;font_size>7&lt;\/font_size>\n            &lt;display_zero>true&lt;\/display_zero>\n            &lt;model>Vendor\\Module\\Model\\Sales\\Pdf\\PayLater&lt;\/model>\n            &lt;sort_order>360&lt;\/sort_order>\n        &lt;\/total>\n    &lt;\/totals>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2:<\/strong>&nbsp;Now create Paynow.php file in Vendor\\Module\\Model\\Sales\\Pdf folder<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This code calculates the amount your shopper paid using the partial payment model. The information used here will shown under \u201cAmount Paying Now\u201d in the PDF.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> Create Paynow.php In Vendor\\Module\\Model\\Sales\\Pdf Folder \n\n&lt;?php\n\nnamespace Vendor\\Module\\Model\\Sales\\Pdf;\n\nuse Magento\\Sales\\Model\\Order\\Pdf\\Total\\DefaultTotal;\n\nclass PayNow extends DefaultTotal\n{\n    \/**\n     * Get array of arrays with totals information for display in PDF\n     * array(\n     *  $index => array(\n     *      'amount'   => $amount,\n     *      'label'    => $label,\n     *      'font_size'=> $font_size\n     *  )\n     * )\n     * @return array\n     *\/\n    public function getTotalsForDisplay(): array\n    {\n        $objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n        $partialpayment = $objectManager->create('\\Vendor\\Module\\Model\\Partialpayment');\n        $partialPayment = $partialpayment->load($this->getOrder()->getIncrementId(),'order_id');\n\n        $paynow = $partialPayment->getPaidAmount();\n\n        if (!$partialPayment->getOrderId()) {\n            return [];\n        }\n        $amountInclTax = $this->getOrder()->formatPriceTxt($paynow);\n        $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;\n\n        return [\n            [\n                'amount' => $this->getAmountPrefix() . $amountInclTax,\n                'label' => __($this->getTitle()) . ':',\n                'font_size' => $fontSize,\n            ]\n        ];\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 3:<\/strong>&nbsp;Create PayLater.php at Vendor\\Module\\Model\\Sales\\Pdf Folder<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This code calculates the remaining amount your shopper needs to pay. The PHP uses the custom partial payment model. The information used here will show under \u201cRemaining Amount\u201d in the PDF.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> Create PayLater.php at Vendor\\Module\\Model\\Sales\\Pdf Folder\n\n&lt;?php\n\nnamespace Vendor\\Module\\Model\\Sales\\Pdf;\n\nuse Magento\\Sales\\Model\\Order\\Pdf\\Total\\DefaultTotal;\n\nclass PayLater extends DefaultTotal\n{\n    \/**\n     * Get array of arrays with totals information for display in PDF\n     * array(\n     *  $index => array(\n     *      'amount'   => $amount,\n     *      'label'    => $label,\n     *      'font_size'=> $font_size\n     *  )\n     * )\n     * @return array\n     *\/\n    public function getTotalsForDisplay(): array\n    {\n        $objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n        $partialpayment = $objectManager->create('\\Vendor\\Module\\Model\\Partialpayment');\n        $partialPayment = $partialpayment->load($this->getOrder()->getIncrementId(),'order_id');\n\n\n        $remainAmount = $partialPayment->getRemainingAmount();\n\n        if (!$partialPayment->getOrderId()) {\n            return [];\n        }\n        $amountInclTax = $this->getOrder()->formatPriceTxt($remainAmount);\n        $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;\n\n        return [\n            [\n                'amount' => $this->getAmountPrefix() . $amountInclTax,\n                'label' => __($this->getTitle()) . ':',\n                'font_size' => $fontSize,\n            ]\n        ];\n    }\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here you make edits to the row based on your requirement. I have considered here the EMI option.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can make edits here based on any shipping charges or discount codes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I hope now you can easily display extra fee to the total order invoice PDF in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><div class=\"meetanshi-cta\">\r\n<div class=\"cta-content-wrapper\">\r\n<span>Magento 2 Extra Fee<\/span>\r\n<p>Increase your average order value with extra fees for additional services.<\/p>\r\n<a href=\"https:\/\/meetanshi.com\/magento-2-extra-fee.html\" target=\"_blank\" class=\"btn-primary\">Start Now<\/a>\r\n<\/div>\r\n<div class=\"cta-image-new\">\r\n<img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/11\/magento-2-extra-fee.png\" alt=\"Magento 2 Extra Fee\">\r\n<\/div>\r\n<\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A detailed invoice is essential to enhance your customers\u2019 shopping experience for them to understand the pricing breakdown of the product completely. For instance, if&#8230;<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2289","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2289"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2289\/revisions"}],"predecessor-version":[{"id":13831,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2289\/revisions\/13831"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}