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

后端 未结 5 883
旧时难觅i
旧时难觅i 2021-01-03 05:52

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 t

相关标签:
5条回答
  • 2021-01-03 06:11

    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.

    0 讨论(0)
  • 2021-01-03 06:16

    Careful if there is NO address set then this getPrimaryBillingAddress() return a non object.

    $address = $this->getCustomer()->getPrimaryBillingAddress();
    if ( $address ) echo $address->getTelephone();
    
    0 讨论(0)
  • 2021-01-03 06:17

    Luis has mentioned before that if customer didn't setup his billing address you will get an error in return: Call to a member function in a non-object.

    If you want to be ready for such situation you can put the code into following IF statement:

    <?php if ($customerAddressId){ ?>
        <?php $address=Mage::getModel('customer/address')->load($customerAddressId); ?>
        <?php $this->getCustomer()->getPrimaryBillingAddress()->getTelephone(); 
    } ?>
    
    0 讨论(0)
  • 2021-01-03 06:28

    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()
    
    0 讨论(0)
  • 2021-01-03 06:34
    isLoggedIn()) { $customer = Mage::getSingleton('customer/session')->getCustomer(); $customerName = $customer->getName(); // like that you can access all other attributes } ?>
    0 讨论(0)
提交回复
热议问题