How To Show Custom Data In Shipping Address Box In Magento 2 Admin
Magento 2 platform is the number one choice for many businesses. However, the default Magento 2 features may not be enough to satisfy all the business requirements. Because of the flexibility of customization, the Magento developers can tweak the default functionalities and improve the shopping platform.
Talking about customization, I have come up with a solution to show custom data in shipping address box in Magento 2 admin panel.
For example, you own a Magento 2 store in India and have to calculate GST. It requires additional fields like CGST and SGST. Using the below code, you can implement displaying custom attributes in shipping address box in Magento 2 admin.
Other examples, such as phone number type or any custom fields added in the checkout step, can be shown in the shipping address box in the admin panel. In addition to this, you can also set up multiple shipping addresses in Magento 2 to allow customers add more than one address.
Method to show custom data in shipping address box in Magento 2 admin:
Go to Stores -> Configuration -> Customers -> Customer Configuration -> Address Templates
Find the HTML section from the address template.
Untick checkbox system value and add the below code. Also, you may change the attribute code if needed. For the email template, same address format [HTML Address format] works fine.
1 |
{{depend mob_type}}Mob_Type: {{var mob_type}}{{/depend}} |
If required, run the below command:
1 |
php bin/magento cache:clean |
An attribute shows at the order view page and order Email also.
With this method, both the addresses are displayed. However, if you want to display only in shipping, you can only put SMS value in shipping address table (sales_order_address and quote_address
) and not billing. It works just fine.
That’s it.
Any doubts in the implementation of the above code? If so, please mention them in the Comments section below and I’d be happy to help.
Do share the solution with fellow Magento developers via social media.
Thanks.
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 Programmatically Assign Products To Multiple Categories In Magento 2
Easy Way to Allow File Attachment in WYSIWYG in Magento 2
Next