0

I cannot get the postcode from Users's billing Address,this is my code, everything works fine except for the postcode, which i'm not able to pull.

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

        $customer = $observer->getEvent()->getCustomer();
        $customer_email=$customer->getEmail();
        $first_name= $customer->getFirstname();
        $last_name= $customer->getLastname();
        $taxVat = $customer->getTaxvat();


        //Billing Address variables

        $billingID = $customer->getDefaultBilling();
        $billingAddress = $objectManager->create('Magento\Customer\Model\Address')->load($billingID);
        $billingCompany = $billingAddress->getCompany();
        $billingZipcode = $billingAddress->getPostCode();
        $billingCity = $billingAddress->getCity();
        $billingState = $billingAddress->getRegion();
        $billingStreet = $billingAddress->getStreet();
        $billingStreet1 = $billingStreet[0];
        $billingStreet2 = $billingStreet[1];
        $billingTelephone = $billingAddress->getTelephone();

Greetings!

2 Answers 2

1

$billingZipcode = $billingAddress->getPostCode();

Should be

$billingZipcode = $billingAddress->getPostcode();

2
  • Hello, for some reasons when I put that method getPostcode(); my form says We can't save the customer, like if the method does not exists. I'm using Magento 2.2.7, If it put the method getPostCode(); it returns nothing but does not throw any error. Jul 23, 2019 at 14:45
  • for some reason it works now, thank you! Jul 30, 2019 at 18:07
0
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$billingAddress = $objectManager->create('Magento\Customer\Model\Address')->load($billingID);

 $billingPostcode = $billingAddress->getPostcode();
1
  • hello , just to let you know, but the method getPostCode(); did not work, the correct one is getPostcode(); with lower case 'c'. Aug 1, 2019 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.