Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: How to display customer's phone number on customer information field

Tags:

magento

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.

like image 590
BlueSun3k1 Avatar asked Aug 07 '12 15:08

BlueSun3k1


People also ask

How can I get customer ID in Magento 2?

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);

How can I get Magento 2 customer billing address?

Thus, it is possible to get a default billing or shipping address ID from a customer by calling its getDefaultBilling() or getDefaultShipping() functions.


2 Answers

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.

like image 124
Alex Hadley Avatar answered Sep 28 '22 06:09

Alex Hadley


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()
like image 25
kalenjordan Avatar answered Sep 28 '22 08:09

kalenjordan