Here’s a little snippet for those of you that need some custom customer coding. In the example below, I’m checking to see if the current user belongs to role named “internal”. You can use similar approach to show or hide some stuff inside your template depending on a customer that is logged in.
<?php $roleId = Mage::getSingleton('customer/session')->getCustomerGroupId(); $role = Mage::getSingleton('customer/group')->load($roleId)->getData('customer_group_code'); $role = strtolower($role); if($role == 'internal') { echo 'Hello internal...'; } ?>
it doesn’t work. I tried to put it in the hello.phtml under template, but it showed below in the frontend
f($role == ‘Wholesale’) { echo ‘Member Type: Wholesale’; } ?>
could you please help?
it’s is correct and that should be showed wholesale, but the code seems hv some errors …
Code is working… I just tested it, placed the following into the top of header.phtml (but you can place it anywhere)… here you go…
< ?php
$roleId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$role = Mage::getSingleton('customer/group')->load($roleId)->getData('customer_group_code');
var_dump($role);
$role = strtolower($role);
if($role == 'wholesale')
{
echo 'Hello wholesale...';
}
?>
p.s. You Need to be looged in as customer… at http://some_server/customer/account/login/
Hey, Thanks for posting this. Saved me from searching the code to figure it out. Some of your other posts have also been helpfull.
How about getting the admin role, not the customer role?
how could i get the current customer address