Site icon MageComp Blog

Magento 2: How to Add New Field at Order Total Block in Order PDF

How to Add New Field at Order Total Block in Order PDF In M2

Hello Magento Friends,

Today’s subject is Magento 2: How to Add New Field at Order Total Block in Order PDF.

When an order is placed, Magento provides the option for customers to download an order PDF that contains all the details of the buyer, seller, and the product that is being purchased. However, you can add some custom fields to order PDF rather than the default format provided by Magento. Learn How to Change Order PDF Format in Magento 2.

Sometimes we need to add some fields in order total and it should reflect in order PDF as well. For e.g, we are going to add a new tax, ABC TAX, and that will be displayed in order total in order view. But also need to add in order PDF which customers will download for their reference. 

So, here I will explain how you can achieve it.

Steps to Add New Field at Order Total Block in Order PDF in Magento 2:

Let us take an example, I have added ABC TAX 

Step 1: Move to the below path

app\code\Vendor\Extension\etc\pdf.xml

Now add the code as follows

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/pdf_file.xsd">
  <totals>
    <total name="abc">
      <title translate="true">ABC TAX</title>
      <source_field>abc_tax</source_field> // it’s Your Database Field Name
      <display_zero>false</display_zero> // If your column has 0 Value then it will not display in Frontend
      <sort_order>550</sort_order> // it will decide where you want to display your field in total block , for e.g after sub total, before grand total etc.
	<font_size>7</font_size> // to give font size.
    <model>Class_Name</model> // to customize the value you can use model class.
    </total>
   <amount_prefix>hello</amount_prefix> // you cann add profiex before amount
  </totals>
</config>

Still, if you want more understanding and customization, you need to understand the Magento core file. Here is the path,

vendor\Magento\Sales\Model\Order\Pdf\Config\Converter.php

To view more tag, you need to check out the following file

vendor\magento\module-sales\etc\pdf_files.xsd

Conclusion:

Hence, this way you can Add New Field at Order Total Block in Order PDF in Magento 2. In case of any difficulty share the issue with me via the comment section. Stay in touch with us so that you do not miss out on any important Magento solution.

Happy Coding!

Exit mobile version