Magento: Check if the customer is logged in and get the customer id, name, email

The code snippet below will check if a customer is logged in. If yes, it will get the customer id, customer name and customer email.

//Get the customer session and check if the customer is logged in
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    // Get the customer object from customer session
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $custID = $customer->getID();//get customer id
    $custName = $customer->getName();//get customer full name
    $custEmail = $customer->getEmail();//get customer email

Search within Codexpedia

Custom Search

Search the entire web

Custom Search