I want to display "As low as $184". The 184 is the price for the highest quantity range.
Something like this mockup:
Screenshot 2025-08-21 at 4.09.07 PM.jpg
Screenshot 2025-08-21 at 3.57.37 PM.jpgScreenshot 2025-08-21 at 4.00.15 PM.jpg
Is there a setting, plugin, or custom solution?
/templates/(your-template)/html/com_virtuemart/productdetails/default.php
$allPrices_key_found = array_reduce(
array_keys($this->product->allPrices), // iterate over allPrices' keys
function ($key_best_so_far, $key_current) {
if($this->product->allPrices[$key_current]['product_price'] < $key_current[$key_best_so_far]['product_price']) {
return $key_current;
} else {
return $key_best_so_far;
}
},
array_key_first($this->product->allPrices) // start with first allPrices' keys
);
echo "Lowest price:<br>";
print_r($this->product->allPrices[$allPrices_key_found]);
Change the if-statement operator from < to > to get most expensive price's item.
Thank you so much for the code!
Unfortunately, this is the result:
Screenshot 2025-08-23 at 3.30.27 PM.jpg
This is the code:
Screenshot 2025-08-23 at 12.46.36 PM.jpg
I'm hoping to display: Lowest price: $184
I ran your code through Ai and got it to work:
// Make sure we have an array to work with.
$allPrices = (isset($this->product->allPrices) && is_array($this->product->allPrices))
? $this->product->allPrices
: [];
// Polyfill for array_key_first for older PHP (<7.3).
if (!function_exists('array_key_first')) {
function array_key_first(array $arr) {
foreach ($arr as $k => $_) { return $k; }
return null;
}
}
echo "Lowest price:<br>";
if (!empty($allPrices)) {
// Initialize with the first key.
$lowestKey = array_key_first($allPrices);
// Walk the array to find the lowest product_price.
foreach ($allPrices as $k => $row) {
if (!isset($row['product_price'])) {
continue;
}
if (
!isset($allPrices[$lowestKey]['product_price']) ||
(float)$row['product_price'] < (float)$allPrices[$lowestKey]['product_price']
) {
$lowestKey = $k;
}
}
$lowestPrice = isset($allPrices[$lowestKey]['product_price'])
? (float)$allPrices[$lowestKey]['product_price']
: null;
echo $lowestPrice !== null ? number_format($lowestPrice, 2) : 'N/A';
} else {
echo 'N/A';
}
THANK YOU for your help!
Maybe I misunderstand the problem, but there is a simple setting for it. In the vmconfig tab prices, there is "Order of multiple prices". So you can decide if the product should show mainly the lowest, or highest price. No resort code in the template needed.
But in anyway thank you for the idea vmfyelloq19. And great that you managed it modernmagic.
Girls From Your City - No Verify - Anonymous Sex Dating
https://SecreLocal.com
Girls In Your City (https://secrelocal.com/girls.html) - Anonymous Adult Dating - No Verify