Magento 2 programatically load default billing and shipping address..
1 Answer
This is an example of getting default customer's billing and shipping address if you have the customerId and using the customerRepository Magento\Customer\Api\CustomerRepositoryInterface
and the addressRepository Magento\Customer\Api\AddressRepositoryInterface
$customer = $this->customerRepository->getById($customerId);
$billingAddressId = $customer->getDefaultBilling();
$shippingAddressId = $customer->getDefaultShipping();
//get default billing address
try {
$billingAddress = $this->addressRepository->getById($billingAddressId);
} catch (\Exception $e) {
//
}
-
the above code returns only the address id .can you help me to load the address by address id..?– srgCommented Aug 4, 2017 at 4:52
-
-
-
_getAddressHtml($billingAddress ) will foramt the address? Commented Oct 5, 2018 at 12:18