I have a magento store with seven different customer groups. My goal is to display a little text - depending on the customer group - under the price at the product page (price.phtml).

Customer Groups: Group0 and Group1 need one text (ex. text for Group01) Group2, Group3 and Group 4 need their own text (ex. text for Group234) Group5, Group6 and Group 7 also need their own text (ex. text for Group567)

So far I have got this working for one customer group:

    $_isLoggedIn = $this->helper('customer')->isLoggedIn();
    if($_isLoggedIn == true){
    $_myGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();          
    if($_myGroupId == 1){
    ?> <br/><span class="price_text"><?php echo $this->__("ex. text for Group01") ?></span>

Now my problem is to change the function to an if-elseif-else... can anyone help me complete this function?

Thank you very much in advance Tina


you can do the quick and dirty way and just have a switch-case for each customer group.
Something like this:

switch ($_myGroupId) {
   case 1:
     echo "TEXT for group 1 here";
   case 2: 
     echo "TEXT for group 2 here";

But this falls over when you have to add an other group.
Here is how I would do it. I would create a system->config section where you get a textarea for each customer group and you use that textarea to fill in the text you need.

Here is a tutorial to create such a section.
Using this, each time you add a new customer group a new textarea will be added so you don't have to code anything.
Then just do this in your template:

<?php echo Mage::getStoreConfig('section_name/group_name/group_'.$_myGroupId);?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.