0

How do i display the telephonenumber on customer dashboard?

I have extended the original class to add some functions, but I can't find the right way to show customer number. I read that telephonenumber that is related to the address.

This is my class:

<?php
namespace Portail\Customer\Block;
use Magento\Customer\Model\Session;

class Info extends \Magento\Customer\Block\Account\Dashboard\Info
{

    public function testTxt(){
        return 'bonjour';
    }

    public function getTelephoneCustomer(){

        $customerData = $this->getCustomer();
        $telephone = $customerData->getDefaultShippingAddress()->getTelephone();

        return $telephone;

    }

}

When I tried to reload my page, the loading is just stop, there no error.

2
  • Look at this: magento.stackexchange.com/questions/125354/… The dashboard is created using multiple .phtml files and included by .xml. The dashboard is customer_account_index.xml (if I recall correctly). Try to combine this, maybe by altering the template Magento_Customer::account/dashboard/info.phtml – Condor Jun 25 '18 at 10:33
  • I've seen this topic, but it's to get the store phone number right ? I want to have the customer number – Morgan Tartreau Jun 25 '18 at 12:18
1

If you have created your custom customer attribute manually, you can simply use this in the phtml:

$objm = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objm->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) 
{
    echo $customerSession->getCustomer()->getCustomAttribute(); //custom_attribute
}
1
  • It's not with a custom attribute, I want to use the native function of magento 2 (through address) – Morgan Tartreau Jun 25 '18 at 12:19
0

Use below code in your info block

enter image description here

0

You can try below code to display TelePhone

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Helper\Session\CurrentCustomerAddress');
echo $customerSession->getDefaultBillingAddress()->getTelephone();

Try To avoid Object-manager approach.

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.