How to get Customer group id in magento

while i was working on one magento site one of my client wants to show a page only for wholesale customer.I knew How to assign customer group in magento But didn't know how to check it.I had to make this condition on Aw_blog module page, I opened that module and wrote the Following code and worked correctly.

First I check whether a Customer logged in or not ,then I fetch the value of customer group id to know in which cutomer group visited this page.In my website Wholesale customer Id was 2.

$login = Mage::getSingleton( 'customer/session' )->isLoggedIn(); //Check if User is Logged In
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); //Get Customers Group ID
if($groupId == 2) //My wholesale customer id was 2 So I checked for 2. You can check according to your requirement
echo 'You are a wholesale Customer';


  1. Anonymous1/31/2011

    Nice, Just what I was looking for, works fine in


  2. hi can any one tell me how can i change the customer groupid as soon as he place order?

  3. Hello, Thank you very much for that code!!!