I have added a phone no text box in Customer Account edit form(Account Edit).

Block file

The issue is, I am not able to get the phone no to get it after the user saved it.

For dob(date of birth)

 <?php $_dob = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>

 <?php if ($_dob->isEnabled()): ?>
       <?= $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
 <?php endif ?>

For Telephone, I am not able to get phone no.

 <?php $_telephone = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Telephone') ?>

 <?php if ($_telephone->isEnabled()): ?>
       <?= $_telephone->setTelephone($block->getCustomer()->getTelephone())->toHtml() ?>
 <?php endif ?>

as error is

Method 'getTelephone' not found in Magento\Customer\Api\Data\CustomerInterface more... 

How can I get Customer telephone no, from this interface Magento\Customer\Api\Data\CustomerInterface


You are not able to get the getTelephone() on Magento\Customer\Api\Data\CustomerInterface because Telephone is part of customer address Magento\Customer\Api\Data\AddressInterface object not for customer object.

So If you want the Telephone then you need to get the address object of the customer then you can get the Telephone value



  • I get this error $block->getAddress()->getTelephone(), because block \Magento\Customer\Block\Form\Edit has so such function getAddress() – summu Apr 24 '19 at 17:52
  • correct, because each address has own telephone number so you need to first select the address then you can get the telephone , but I think you know the reason error which you are getting :) @summu – Keyur Shah Apr 25 '19 at 9:33

I used this code in order to get default phont number in the edit form...

$customer = $block->getCustomer();
$defaultBillingAddressId = $customer->getDefaultBilling();
$addressesArr = $customer->getAddresses();
$defaultShippingAddress = $addressesArr[$defaultBillingAddressId - 1];
echo $defaultShippingAddress->getTelephone();

The problem is that my phone number doesn't saved when submit the form.

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.