Sunday 20 March 2016

Magento : Get Logged In Customer’s Group ID

<?php
/* Check if customer is logged in */
$isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
/* If customer is logged in */
if($isLoggedIn) :
    /* Get the logged in customer's group ID */
    $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    /* Check if the logged in customer's group ID matches with the ID you are after */
    /* Customer group IDs are listed against each group under Admin > Customers > Customer Groups */
    if($customerGroupId == 3) :
        echo 'Welcome Retailer';
    endif;
endif;
?>

You can also write static blocks or custom variables to contain group specific information. You can name the static block identifier based on the $customerGroupId and retrieve it on the front end.

No comments:

Post a Comment