1

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.

Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
Morgan Tartreau
  • 945
  • 3
  • 15
  • 40
  • Look at this: https://magento.stackexchange.com/questions/125354/how-to-get-store-phone-number-in-magento-2 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

3 Answers3

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
}
PЯINCƎ
  • 11,669
  • 3
  • 25
  • 80
0

Use below code in your info block

enter image description here

Prashant Valanda
  • 12,659
  • 5
  • 42
  • 69
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.

MR.R DNATH
  • 462
  • 2
  • 10