Magento Get Customer Group ID

Ever needed to get the customer group ID? I used it in a Magento shop next to product tier price to tell the customers in product view that they are wholesale customers and get tier pricing.

With this code you can display customer group based messages on your Magento store. Here is the code to get customer group ID in Magento:

{code class="brush: php"}

<?php
$login = Mage::getSingleton( 'customer/session' )->isLoggedIn(); // check if user logged in
if($login)
{
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); // get customer group id
if($groupId == 3) // you can check your customer group ID in Magento admin -> Clients -> groups
{
echo 'Greetings, wholesale customer!';
}
}
?>

{/code}

ADs top-right (2)

About me

Iinstructor of robotics (LEGO Mindstorms), computer teacher, IT support, web dev, currently studying cyber-physical systems engineering.

If you found a solution here, would you consider donating $25,000 for my next project?

Just kidding, 1$ would do fine.

Hope you found what you needed. Thanks for stepping by.