Magento 2 – How to Get Customer Address by Address ID addressmagento2PHPshippingshipping-address Can i get customer address like picture below with address id? If i can, how should i do it? Best Answer You can get the formatted address using address id with below code: public function __construct( \Magento\Customer\Api\AddressRepositoryInterface $addressRepository, \Magento\Customer\Model\Address\Config $addressConfig, \Magento\Customer\Model\Address\Mapper $addressMapper, ) { $this->addressRepository = $addressRepository; $this->_addressConfig = $addressConfig; $this->addressMapper = $addressMapper; } public function getFormattedAddress($addressId) { try { $addressObject = $this->addressRepository->getById($addressId); /** @var \Magento\Customer\Block\Address\Renderer\RendererInterface $renderer */ $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer(); return $renderer->renderArray($this->addressMapper->toFlatArray($addressObject)); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { return null; } } Related SolutionsMagento – Get shipping methods from address in multi-address shipping There are many ways to do this but i am sharing with you the best method i know of. - See more at: Detail LINK let me know if i can help you more EDIT Here i am giving you sudo code if ($this->_checkChangedAddress($bill_data, 'Billing', $bill_addr_id) || $this->getRequest()->getPost('payment-method', false)) { if (isset($bill_data['email'])) { $bill_data['email'] = trim($bill_data['email']); } $bill_result = $this->getOnepagecheckout()->saveBilling($bill_data, $bill_addr_id, false); if (!isset($bill_result['error'])) { $pmnt_data = $this->getRequest()->getPost('payment', array()); $this->getOnepagecheckout()->usePayment(isset($pmnt_data['method']) ? $pmnt_data['method'] : null); $result['update_section']['payment-method'] = $this->_getPaymentMethodsHtml(); if (isset($bill_data['use_for_shipping']) && $bill_data['use_for_shipping'] == 1 && !$this->getOnepagecheckout()->getQuote()->isVirtual()) { $result['update_section']['shipping-method'] = $this->_getShippingMethodsHtml(); $result['duplicateBillingInfo'] = 'true'; $ship_updated = true; } } else { $result['error_messages'] = $bill_result['message']; } } Magento – How to Get Customer Address Thee address information is stored within the Mage_Customer_Model_Customer so you should be able to create an instance of it with the customer id. $customer = Mage::getModel('customer/customer')->load($customerId); Then depending on the type of address that you are looking for you should be able to call one of the following functions. Primary Billing Address: $customer->getPrimaryBillingAddress(); Primary Shipping Address: $customer->getPrimaryShippingAddress(); General Address Selection: $customer->getAddressItemById(); As to the country information, by ID do you mean the ISO standard code for the country eg FR, GB etc in which case you could try: $countryName = Mage::getModel('directory/country')->load('FR')->getName(); echo $countryName; // Should output France in this example Magento Customer Model API Documentation: http://docs.magentocommerce.com/Mage_Customer/Mage_Customer_Model_Customer.html Related TopicMagento – How to Get All Billing Addresses ProgrammaticallyMagento 2 – How to Get Customer Address by Customer IDMagento – How to update customer address using custom Api in magento2
Best Answer
You can get the formatted address using
address id
with below code: