I’m trying to have the customer’s phone number show under the customer account information section. I know the phone number belongs to the customer address section but I’m trying to redesign how the customer account information looks like.
I added a new custom field for Customer ID and I’m able to display it by using the following code as the customer ID belongs to customer_entity.
<?php echo $this->__('Identification:') ?><?php echo $this->htmlEscape($this->getCustomer()->getCustid()) ?>
but now I’m trying to do the same for the telephone number by using this
<?php echo $this->__('Telephone:') ?><?php echo $this->htmlEscape($this->getCustomer()->getTelephone()) ?>
But it doesn’t display any data since it belongs to customer_address_entity and I BELIEVE it should be
->getAddress()->getTelephone()
instead of
->getCustomer()->getTelephone()
but using ->getAddress just gives me an error “ Call to a member function getTelephone() on a non-object “
Does anyone have any idea how to do this?
As a reference, I'm trying to have this data display on the file customer\account\dashboard\info.phtml
Thanks in advance.
Use the following code to load Customer by ID using Object Manager in your Magento store. $customerId=1; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerData = $objectManager->create('Magento\Customer\Model\Customer')->load($customerId);
Thus, it is possible to get a default billing or shipping address ID from a customer by calling its getDefaultBilling() or getDefaultShipping() functions.
Oh, thanks I'll post now! (see comments under original post).
Simply use the following:
$this->getCustomer()->getPrimaryBillingAddress()->getTelephone();
The first part will give you all the details, which you could then explore with var_dump()
as per @paperids.
This answer should go to @Alex, but just for the sake of completion, I'm posting this as an answer:
Use:
$this->getCustomer()->getPrimaryBillingAddress()->getTelephone()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With