How to get Magento customer ID
In Magento, you can get the customer ID of a logged-in customer using the following code:
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customerId = $customer->getId();
This code first gets the customer session, and then calls the getCustomer
method to get the customer object. The getId
method is then called on the customer object to get the customer's ID.
If you want to get the customer ID by email, you can use the following code
$customer = Mage::getModel('customer/customer')->loadByEmail($email);
$customerId = $customer->getId();
This code loads the customer object by passing the email to the loadByEmail
method, and then calls the getId
method to get the customer's ID.