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.
{{depend mob_type}}Mob_Type: {{var mob_type}}{{/depend}}
If required, run the below command:
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.
Do share the solution with fellow Magento developers via social media.
Thanks.