Magento 2 get shipping and billing address by order id


Check below code snippet to get shipping and billing address of order by order id.


$orderid = 2;
 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Api\Data\OrderInterface')->load($orderid);
 
//fetch whole billing information
print_r($order->getBillingAddress()->getData());
 
//Or fetch specific billing information
echo $order->getBillingAddress()->getCity();
echo $order->getBillingAddress()->getRegionId();
echo $order->getBillingAddress()->getCountryId();
 
//fetch whole shipping information
print_r($order->getShippingAddress()->getData());
 
//Or fetch specific shipping information
echo $order->getShippingAddress()->getCity();
echo $order->getShippingAddress()->getRegionId();
echo $order->getShippingAddress()->getCountryId();
Previous
Next Post »