Get the Value of the Cheapest Option for an Ubercart Product
This is just a quick code example. Imaging you have an Ubercart attribute that has several options and you’d like to show an “As low as $X.XX” price on the frontend. Here’s a simple solution. Note that if you wanted the lowest price across ALL attributes you could loop through each attribute too (instead of just looking at attributes[1]).
1 2 3 4 5 6 7 8 9 |
if ($node->attributes[1]->options) { // Get lowest price of all "Units" attribute options $prices = array(); foreach ($node->attributes[1]->options as $opt) { $prices[] = $opt->price; } $output .= t('As low as !price', array('!price' => uc_currency_format(min($prices)))); } |