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!

1

$billingZipcode = $billingAddress->getPostCode();

Should be

$billingZipcode = $billingAddress->getPostcode();

  • 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. – Oscar Vazquez Jul 23 at 14:45
  • for some reason it works now, thank you! – Oscar Vazquez Jul 30 at 18:07
0
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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