How to Add New Field at Order Total Block in Order PDF on Magento 2?
Today, we’re going to teach you guys how to add a new field at order total block in order PDF in your Magento 2 store.
In Magento 2, you can offer an option for your customers to download their order PDF containing all the details of the product that is purchased.
And the best part is, you can also even add a new custom field to the order PDF file.
This is quite useful especially when you need to add some extra fields for either product detail or new tax field.
In this post, we will show you exactly how to add a new custom field at order total block in order PDF in your Magento 2 store.
Method to Add a New Field at Order Total Block in Order PDF in Magento 2
In this tutorial, we will show you how to add a dummy tax (ABC TAX) and display it in order total block as well as in order PDF in your Magento 2 store.
First of all, open the pdf.xml file in the app\code\Vendor\Extension\etc\ folder and paste the following code:
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:module:Magento_Sales:etc/pdf_file.xsd”>
<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.
<amount_prefix>hello</amount_prefix> // you cann add profiex before amount
And that’s about it!
This is the easiest way to add a new custom field at order total block in order PDF in your Magento 2 store.
We hope that you found this tutorial helpful. If you have any doubts, please ask them in the comments below.
And if you need our professional assistance, feel free to contact us at any time.