---
title: "How to Convert Shipping Address into HTML Format using Magento 2?"
url: "https://magecomp.com/blog/convert-shipping-address-into-html-format-magento-2/"
date: "2023-08-18T16:05:33+00:00"
modified: "2025-02-13T12:32:58+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 481
reading_time: "3 min read"
summary: "Hello Magento Friends,"
description: "Improve the user experience of your Magento 2 store by showing the shipping address in a proper format. Learn How to Convert Shipping Address into HTML Forma..."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Top 5 Magento 2 Store Pickup Extensions"
    url: "https://magecomp.com/blog/top-magento-2-store-pickup-extensions/"
  - title: "How to Get Product Salable Quantity in Magento 2?"
    url: "https://magecomp.com/blog/get-product-salable-quantity-magento-2/"
  - title: "How to Create Custom Payment Method in Magento 2?"
    url: "https://magecomp.com/blog/create-custom-payment-method-in-magento-2/"
---

# How to Convert Shipping Address into HTML Format using Magento 2?

_Published: August 18, 2023_  
_Author: Dhiren Vasoya_  

![How to Convert Shipping Address into HTML Format using Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/08/How-to-Convert-Shipping-Address-into-HTML-Format-using-Magento-2-1024x512.webp)

**Hello Magento Friends,**

In today’s Magento 2 guide, I will explain How to Convert Shipping Address into HTML Format using Magento 2?
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-1.webp)](https://magecomp.com/services/hire-magento-programmer/)

The shipping address information for eCommerce businesses helps to successfully deliver orders to customers. However, presenting this address in a visually appealing and organized format on your website can enhance the user experience and improve the overall professionalism of your store.
Let’s learn How to Convert Shipping Address into HTML Format using Magento 2.
## Steps to Convert Shipping Address into HTML Format using Magento 2:
**Step 1:** Create a **Data.php** file inside the Helper folder.
**app\code\Vendor\Extension\Helper**

Then add the code as follows.
```
<?php
namespace VendorExtensionHelper;

use MagentoFrameworkAppHelperAbstractHelper;

class Data extends AbstractHelper
{
   protected $orderRepository;
   protected $_addressConfig;

   public function __construct(
         MagentoSalesApiOrderRepositoryInterface $orderRepository,
         MagentoCustomerModelAddressConfig $addressConfig
         )
   {
       $this->orderRepository = $orderRepository;
       $this->_addressConfig = $addressConfig;
   }

   public function _getAddressHtml($orderId)
    {
        try {
            $order = $this->orderRepository->get($orderId);
        } catch (NoSuchEntityException $e) {
            throw new MagentoFrameworkExceptionLocalizedException(__('This order no longer exists.'));
        }
        $address = $order->getShippingAddress();
        $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
        return $renderer->renderArray($address);
    }
}
```

**Step 2:** Now, create the **Address.php** file inside the Block folder.
**app\code\Vendor\Extension\Block**

Then add the code as below.
```
<?php

namespace VendorExtensionBlock;
use VendorExtensionHelperData as Helper;

class Address extends MagentoFrameworkViewElementTemplate
{
    /**
     * @param MagentoBackendBlockTemplateContext $context
     * @param MagentoFrameworkRegistry             $registry
     * @param MagentoFrameworkDataFormFactory     $formFactory
     * @param array                                   $data
     */

     protected $helper;

    public function __construct(
        MagentoBackendBlockTemplateContext $context,
        MagentoFrameworkDataFormFactory $formFactory,
         Helper $helper,
        array $data = []
    )
    {
       parent::__construct($context, $data);
       $this->helper = $helper;
    }

    public function getAddressHtml($orderId)
    {
       return $this->helper->_getAddressHtml($orderId);

    }
}
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-1.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Step 3:** Then, create a layout file inside the layout folder.
**Vendor/Extension/view/frontend/layout/your_layout_file.xml**

Add the code as follows.
```
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block template="Vendor_Extension::template.phtml" class="VendorExtensionBlockAddress" name="address.html"/>
        </referenceContainer>
    </body>
</page>
```

**Step 4:** Now, create a t**emplate.phtml** file inside the templates folder
**Vendor/Extension/view/frontend/templates/template.phtml**

Then add the code as given below.
```
<?php
    $orderId = 1;
    $shippingAddress = $block->getAddressHtml($orderId);
    $shippingFormat = strip_tags($shippingAddress);
    echo $shippingFormat;
?>
```

## Conclusion:
By following these steps, you can easily modify the shipping address display to match your store’s design and branding, contributing to a more polished and professional online shopping experience. You can also [**Add Shipping Address Details in Order Grid in Magento 2**](https://magecomp.com/blog/add-shipping-address-details-in-order-grid-in-magento-2/).
If you have any difficulty converting the shipping address into HTML format, you can drop a comment here.
[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2023/04/Magento-Malware-Removal-CTA-1.webp)](https://magecomp.com/magento-malware-removal.html)

**Happy Coding!**

</body>


---

_View the original post at: [https://magecomp.com/blog/convert-shipping-address-into-html-format-magento-2/](https://magecomp.com/blog/convert-shipping-address-into-html-format-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-07-06 09:57:53 UTC_  
