How To

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

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!

Click to rate this post!
[Total: 2 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

Magento 2: Add Quantity Increment and Decrement on Category Page

Hello Magento Friends, In this blog, we will discuss about adding quantity increment and decrement…

17 hours ago

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

4 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

6 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

6 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

7 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

1 week ago