I know we can get formated customer addresses by calling,

$data = $customer->getPrimaryBillingAddress()->getFormated();

Is there a similar way to get shipping address and billing address of a order as a string?

This gives me a error

  • Oops silly mistake. getData was the problem – Dan Jan 13 '16 at 8:48
$billing = $order->getBillingAddress()->getFormated();
$shipping = $order->getShippingAddress()->getFormated();

getFormated supports an optional parameter that can be html or text.

| improve this answer | |
  • What I want is formated order shipping address. Not customer shipping address – Dan Jan 13 '16 at 8:45
  • 1
    @Dan. Sorry, I should read more carefully. I edited the answer. – Marius Jan 13 '16 at 8:49
  • 1
    Hey guys, great question and answers, however I have a slight problem, what if address line 2 is supplied, how do I get that? – K.I Mar 14 '17 at 10:45
  • getFormated() is returning null inside Observer, using $order = $observer->getOrder(). Any idea why? – Braza Aug 23 '18 at 15:55

For some reason inside custom module observer on Magento 2.3 it didn't worked for me so I wrote below code for address summary. You can copy and save time ;)

$shipping_address = $order->getShippingAddress();
echo $shipping_address->getData("firstname").' '.$shipping_address->getData("lastname")."<br/>".
"T: ".$shipping_address->getData("telephone");
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.