I'm trying to get the Customer Group from the customer's order. I have the following code and I have commented the line that doesn't appear to be working;

<?php if($order->getCustomerId()):?>

    // Correctly gets the CustomerId from the $order
    <?php $customerId = Mage::getModel('customer/customer')->load($order->getCustomerId())?>

    // Here i'm trying to get the Customer Group but it's not being returned
    <?php $customer_group_id = Mage::getModel('customer/customer')->load($order->getCustomerGroupId()); ?>
    <?php $customerGroup = Mage::getModel('customer/group')->load($customer_group_id)->getCode() ?>

    <?php echo $customerGroup ?>

<?php endif; ?>

I wondered if someone could help me rectify this?

Thank you.


You should be nearly there. Actually the 7th line is not required and messes up the script

$customer = Mage::getModel('customer/customer')->load($order->getCustomerId())
$customerGroup = Mage::getModel('customer/group')->load($customer->getCustomerGroupId())->getCode();
|improve this answer|||||
  • Thanks @sander-mangel. For some reason it still doesn't echo out the customer group. Even though i know that the customer is a registered user assigned to a customer group. – doubleplusgood Dec 9 '15 at 15:32
  • 1
    Got it. The last line needed to be: <?php $customerGroup = Mage::getModel('customer/group')->load($order->getCustomerGroupId())->getCode();?> – doubleplusgood Dec 9 '15 at 15:35
  • Great, glad it works – Sander Mangel Dec 9 '15 at 16:31

Try This;

<?php if ($order->getCustomerGroupId()): ?>
    <?php $customerGroup = Mage::getModel('customer/group')->load($order->getCustomerGroupId()); ?>
    <?php echo $customerGroup->getCustomerGroupCode(); ?>
<?php endif; ?>
|improve this answer|||||

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.