
This tutorial is to teach you how to hack the price.tpl.php layout for Virtuemart. Today, one of my client ask us if it is possible to hide the discount price for unregistered user, only show the discounted price to the registered user. As I remember from the template file there’s a file called price.tpl.php, so it is a GO for us to tell the client right away it is doable.
Step 1 – Adding the top if statement
So there’s 2 group of people you want to show different price scheme.
- Registered User to show all
- Un-registered User to only show regular price
Let’s add this line of codes on the top of the following code.
<?php // DISCOUNT: Show old price!
Like below
<?php
if ($auth['user_id'] > 0) { // show discounted price only if users logged-in
?>
<?php
// DISCOUNT: Show old price!
Step 2 – Adding extra class to display the pricing differently.
Before
<?php
// DISCOUNT: Show the amount the customer saves
if(!empty($discount_info["amount"])) {
echo "<br />";
echo $VM_LANG->_('PHPSHOP_PRODUCT_DISCOUNT_SAVE').": ";
if($discount_info["is_percent"]==1) {
echo $discount_info["amount"]."%";
}
else {
echo $CURRENCY_DISPLAY->getFullValue($discount_info["amount"]);
}
}
?>
After
<?php
// DISCOUNT: Show the amount the customer saves
if(!empty($discount_info["amount"])) {
echo "<br />";
echo "<span class=\"product-you-save\">"; // add span to text for percent saved
echo $VM_LANG->_('PHPSHOP_PRODUCT_DISCOUNT_SAVE').": ";
if($discount_info["is_percent"]==1) {
echo $discount_info["amount"]."%";
}
else {
echo $CURRENCY_DISPLAY->getFullValue($discount_info["amount"]);
}
echo "</span>"; // add span to text for percent saved
}
?>
Step 3 – Adding the class to differentiate the discounted price
This two class will add a red color to it, and putting a line through it on your old price tag. You will need to add the css code into your template file.
.product-Old-Price {
text-decoration:line-through;
}
.product-Old-Price, .product-you-save {
color:#C01122;
}
Step 4 – Closing the top if statement
Only registered user can see the discounted price and the price you save right for the below code.
<?php
} else { // show discounted price only if users logged-in
?>
<span class="productPrice">
<?php
if(!empty($discount_info["amount"])) {
echo $CURRENCY_DISPLAY->getFullValue($undiscounted_price);
} else {
echo $CURRENCY_DISPLAY->getFullValue($base_price);
}
?>
</span>
<?php
echo $price_table;
}
?>
Be a link sponsor for this page now
[sponsorbox]
I hope you have enjoyed this post, be sure to subscribe to my rss feed by click the subscribe button at the top.
Good Luck!



Whilst this hack certainly does what it says and hides the discount from users that are not logged it, it unfortunately doesn't effect the price that the product is added to the cart with.
I.e The product shows on the front end without being logged in as £15 and once logged in it shows the discount amount and new price, £12 for example, but when not logged in if the product is added to the cart it is still added as the discounted price of £12.
Anyway round this?
Anyway?
hi,
ı have replaced your attached file nothing changes on product pages, am i missing something?
yes this only change the price that is shown not the price that the system use