0

How can I hide the php code below from certain customer group ids 5,6,7? My code below of what I have thus far.

<?php
    $isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
if($isLoggedIn):
        $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    if(in_array($customerGroupId, array('5','6','7'))):

                <?php  if($quotedFeeType == 'fob' && $code != "flatrate") continue; ?>
                <?php  if(($quotedFeeType == 'ddp' || $quotedFeeType == 'cif') && $code != "tablerate") continue; ?> 
        endif;  
 endif; 
?>          

Thank you

  • 1
    I've edited your question with the use of in_array. Take a look if it's working now. – Jonathan Ribas Feb 28 '17 at 16:00
1

You can do that as the following:

/* 1 - Check if customer is logged in */
$isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
/* If customer is logged in */
if($isLoggedIn) :
    /* 2-  Get the logged in customer's group ID */
    $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    /* 3 - 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(in_array($customerGroupId, array('5','6','7'))) :
        // Your Code Here
    endif;
endif;
1

This is what you need:

$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$group = Mage::getModel('customer/group')->load($groupId);  
if(Mage::getSingleton('customer/session')->isLoggedIn() && ($group->getCode()!=5 && $group->getCode()!=6 && $group->getCode()!=7)):

// Will not been visible to customers in group 5,6 or 7

endif;
1
<?php $groupIds = array(generalGroup=>'5', specialGroup=>'6', customGroup=>'7'); ?>

<?php if (!array_search(Mage::getSingleton('customer/session')->getCustomerGroupId(), $groupIds)) : ?>
      // The code to hide...
<?php endif;?>

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.