Magento: Get product price given a customer group

Magento: Get product price given a customer group

August 26, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Get product price given a customer group

Displaying Multiple Prices for Magento Products Based on Customer Group

In Magento 1.7, you can create promotional price rules for specific customer groups, which allows you to offer special discounts to certain segments of your audience. To display both the regular and discounted prices associated with a product, we need to use the appropriate methods provided by Magento.

Understanding Magento’s Price Structure

Magento manages product pricing through tiered pricing and special prices. Tiered pricing allows you to set different prices for products based on the quantity ordered, while special prices are used for temporary discounts or promotions targeted at specific customer groups.

Displaying Prices Based on Customer Group

Unfortunately, there isn’t a direct method like getPriceByCustomerGroup() in Magento 1.x. However, we can achieve this by combining several built-in functions:

$regular_price = $_product->getPrice();
$special_price = $_product->isSaleable() && $_product->getSpecialToDate('none') > Mage::now() ? $_product->getSpecialPrice() : null;

Here’s a breakdown of the code:

  1. $regular_price = $_product->getPrice();: This line retrieves the regular price of the product.

  2. The ternary operator ($_product->isSaleable() && $_product->getSpecialToDate('none') > Mage::now()) ? $_product->getSpecialPrice() : null; checks if there is an active special price for this product and returns it if applicable; otherwise, it returns null.

Incorporating Customer Group Logic

To display the correct prices based on the customer’s group membership, we need to check which customer group is currently logged in. You can use the following code:

$customer = Mage::getSingleton('customer/session')->getCustomer();
if ($customer->hasAddresses()) {
    $current_customer_group_id = $customer->getGroupId();
} else {
    $current_customer_group_id = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
}

This retrieves the ID of the customer group for the currently logged-in user. If no user is logged in, it defaults to the non-logged-in customer group ID.

Putting It All Together

To display both prices on your product view page, you can use a layout update XML file or modify your template files directly:

<reference name="product.info">
    <block type="core/text" name="regular_price" output="toHtml" template="custom/regular_price.phtml"/>
</reference>

In your regular_price.phtml template, you can use the following code:

<?php $regular_price = $_product->getPrice(); ?>
Regular Price: <?php echo Mage::helper('core')->currency($regular_price); ?>

<?php if ($special_price !== null): ?>
    Special Price (for members only): <?php echo Mage::helper('core')->currency($special_price); ?>
<?php endif; ?>

This code retrieves and displays both the regular price and the special price (if applicable) for the currently logged-in customer.

Conclusion

In Magento 1.7, displaying multiple prices for products based on a customer’s group requires combining several built-in functions to retrieve the necessary pricing information. By using these methods correctly, you can provide a seamless shopping experience for your customers by offering targeted promotions and discounts based on their group membership.

Remember that pricing logic in Magento is complex due to its flexibility, so it’s essential to thoroughly test any customizations or modifications to ensure they work as expected across different scenarios. For more advanced pricing rules and configurations, consider exploring the Advanced Pricing Rules guide on our blog for a deeper understanding of Magento’s pricing system.

Happy coding!

Magento 1 Catalog Orders Customers

Our network