How to get formated order addresses
-
13-04-2021 - |
题
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()
解决方案
$billing = $order->getBillingAddress()->getFormated();
$shipping = $order->getShippingAddress()->getFormated();
getFormated
supports an optional parameter that can be html
or text
.
其他提示
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");