How To Get Customer Address Data By Address ID In Magento 2 Programmatically

To get the customer address data by address id in Magento 2

Directory

Create the GetCustomerAddress.php file in the directory mentioned below,

app/code/VendorName/ModuleName/Model/GetCustomerAddress.php

Content of GetCustomerAddress.php

<?php
namespace VendorName\ModuleName\Model;
use Magento\Customer\Api\AddressRepositoryInterface;
class GetCustomerAddress
{
private $addressRepository;
public function __construct(
AddressRepositoryInterface $addressRepository
)
{
$this->addressRepository = $addressRepository;
}
public function getAddressDataById($addressId)
{
try {
$addressData = $this->addressRepository->getById($addressId);
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
};
return $addressData;
}
}
We are providing the best Magento 2 Extensions at the lowest prices. 
Related Products