Magento 2 how to get Postcode from billing address in observer?
-
08-03-2021 - |
Pergunta
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!
Solução
$billingZipcode = $billingAddress->getPostCode();
Should be
$billingZipcode = $billingAddress->getPostcode();
Outras dicas
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$billingAddress = $objectManager->create('Magento\Customer\Model\Address')->load($billingID);
$billingPostcode = $billingAddress->getPostcode();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange