How to display a product price from another shopper group in Virtuemart

This is a common situation where you have different prices per shopper groups on your Virtuemart store.

For example, you have a public price and a member price. When a customer browses your products, you would like to promote the membership advantages and for example display the reduced price the customer could get.

By default, Virtuemart shows only the prices for the current shopper group.

Here is a piece of code you can implement in your template overrides to display the price of another shopper group:

/* DAYCOUNTS : Show Member price : BEGIN */
$loadForShopperGroupId = 8; //This is the id of the shopper group prices to display
$productModel = VmModel::getModel('product');
$shoppergroupsprices = $productModel->loadProductPrices($product->virtuemart_product_id,$quantity,array($loadForShopperGroupId),true);
foreach ($shoppergroupsprices as $sgPrice) {
if ($sgPrice['virtuemart_shoppergroup_id'] == $loadForShopperGroupId) {
$clubprice = $sgPrice['product_price'];
if ($sgPrice['override']==1) {
$clubprice = $sgPrice['product_override_price'];
} else if ($sgPrice['override']==-1) {
//get VatTax
$total_vat_tax = 0;
foreach ($product->prices['VatTax'] as $vat_tax) {
$total_vat_tax = $total_vat_tax + $vat_tax[1];
$total_vat_tax = 1 + ($total_vat_tax / 100);
$clubprice = $sgPrice['product_override_price'] * $total_vat_tax;
echo 'Member price: '. $this->currency->priceDisplay($clubprice,0,1,false,2,'Member price' );
/* DAYCOUNTS : Show Member price : END */

this code can be placed in the foreach loop of the category page for example.

If you were to place this code in the product detail template, make sure to define the $product variable with $product = $this->product; as $product is not known there.

Note: This code applies to Virtuemart 2.x only.

Get CComment PRO and let your users comment!
VM uikit