Magento – Get customer group from order

customercustomer-groupmagento-1.9orders

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.

Best Answer

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();
Related Topic