Magento 2: How to add customer address programmatically?

 

How to add customer address programmatically?

                        
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$state = $objectManager->get('\Magento\Framework\App\State');
$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');
$address = $addresss->create();
$address->setCustomerId($customer->getId())
->setFirstname($firstName)
->setLastname($lastName)
->setCountryId('IN')
->setPostcode(10000)
->setCity('HaNoi')
->setTelephone(123456789)
->setFax(123456789)
->setCompany('Company')
->setStreet('Street')
->setIsDefaultBilling('1')
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
$address->save();

                       
 

Share this

Related Posts

Previous
Next Post »

Pageviews from the past week