Pergunta

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

$order->getBillingAddress()->getData()->getFormated()
Foi útil?

Solução

$billing = $order->getBillingAddress()->getFormated();
$shipping = $order->getShippingAddress()->getFormated();

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

Outras dicas

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/>".
$shipping_address->getData("company")."<br/>".
$shipping_address->getData("street")."<br/>".
$shipping_address->getData("city")."<br/>".
$shipping_address->getData("region")."<br/>".
$shipping_address->getData("country_id")."<br/>".
$shipping_address->getData("postcode")."<br/>".
"T: ".$shipping_address->getData("telephone");
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top