Skip to main content
added 150 characters in body
Source Link
user53909
user53909

I Did check and its working proper

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');

        $address = $addresss->create();

        $address->setCustomerId($customerId)

            ->setFirstname($FirstName)

            ->setLastname($LastName)

            ->setCountryId($countryid)

            ->setPostcode($postcode)

            ->setCity($city)

            ->setTelephone($telephone)

            ->setFax($fax)

            ->setCompany($Company)

            ->setStreet($Street)

            ->setRegion($region)

            ->setSaveInAddressBook('1');

        $address->save();

And if you want to set default billing & shipping address just add 2 line like below

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');

        $address = $addresss->create();

        $address->setCustomerId($customerId)

            ->setFirstname($FirstName)

            ->setLastname($LastName)

            ->setCountryId($countryid)

            ->setPostcode($postcode)

            ->setCity($city)

            ->setTelephone($telephone)

            ->setFax($fax)

            ->setCompany($Company)

            ->setStreet($Street)

            ->setRegion($region)

            ->setIsDefaultBilling('1')

            ->setIsDefaultShipping('1')

            ->setSaveInAddressBook('1');

        $address->save();

I Did check and its working proper

$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');

        $address = $addresss->create();

        $address->setCustomerId($customerId)

            ->setFirstname($FirstName)

            ->setLastname($LastName)

            ->setCountryId($countryid)

            ->setPostcode($postcode)

            ->setCity($city)

            ->setTelephone($telephone)

            ->setFax($fax)

            ->setCompany($Company)

            ->setStreet($Street)

            ->setRegion($region)

            ->setSaveInAddressBook('1');

        $address->save();

And if you want to set default billing & shipping address just add 2 line like below

$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');

        $address = $addresss->create();

        $address->setCustomerId($customerId)

            ->setFirstname($FirstName)

            ->setLastname($LastName)

            ->setCountryId($countryid)

            ->setPostcode($postcode)

            ->setCity($city)

            ->setTelephone($telephone)

            ->setFax($fax)

            ->setCompany($Company)

            ->setStreet($Street)

            ->setRegion($region)

            ->setIsDefaultBilling('1')

            ->setIsDefaultShipping('1')

            ->setSaveInAddressBook('1');

        $address->save();

I Did check and its working proper

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');

        $address = $addresss->create();

        $address->setCustomerId($customerId)

            ->setFirstname($FirstName)

            ->setLastname($LastName)

            ->setCountryId($countryid)

            ->setPostcode($postcode)

            ->setCity($city)

            ->setTelephone($telephone)

            ->setFax($fax)

            ->setCompany($Company)

            ->setStreet($Street)

            ->setRegion($region)

            ->setSaveInAddressBook('1');

        $address->save();

And if you want to set default billing & shipping address just add 2 line like below

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');

        $address = $addresss->create();

        $address->setCustomerId($customerId)

            ->setFirstname($FirstName)

            ->setLastname($LastName)

            ->setCountryId($countryid)

            ->setPostcode($postcode)

            ->setCity($city)

            ->setTelephone($telephone)

            ->setFax($fax)

            ->setCompany($Company)

            ->setStreet($Street)

            ->setRegion($region)

            ->setIsDefaultBilling('1')

            ->setIsDefaultShipping('1')

            ->setSaveInAddressBook('1');

        $address->save();
Source Link
user53909
user53909

I Did check and its working proper

$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');

        $address = $addresss->create();

        $address->setCustomerId($customerId)

            ->setFirstname($FirstName)

            ->setLastname($LastName)

            ->setCountryId($countryid)

            ->setPostcode($postcode)

            ->setCity($city)

            ->setTelephone($telephone)

            ->setFax($fax)

            ->setCompany($Company)

            ->setStreet($Street)

            ->setRegion($region)

            ->setSaveInAddressBook('1');

        $address->save();

And if you want to set default billing & shipping address just add 2 line like below

$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');

        $address = $addresss->create();

        $address->setCustomerId($customerId)

            ->setFirstname($FirstName)

            ->setLastname($LastName)

            ->setCountryId($countryid)

            ->setPostcode($postcode)

            ->setCity($city)

            ->setTelephone($telephone)

            ->setFax($fax)

            ->setCompany($Company)

            ->setStreet($Street)

            ->setRegion($region)

            ->setIsDefaultBilling('1')

            ->setIsDefaultShipping('1')

            ->setSaveInAddressBook('1');

        $address->save();