Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am working on an online store using Woocommerce, many products have variations in size and price. Is there a way to have the range of prices (highest to lowest) of the variations on the product page?

share|improve this question
    
can we see the code displaying your variations? –  Tom J Nowell Mar 25 '13 at 13:57
add comment

3 Answers

up vote 1 down vote accepted

try it like this:

/**
* This code should be added to functions.php of your theme
**/
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);

function custom_variation_price( $price, $product ) {
$price = '';

if ( !$product->min_variation_price || $product->min_variation_price !== $product->max_variation_price ) $price .= '<span class="from">' . _x('From', 'min_price', 'woocommerce') . ' </span>';
$price .= woocommerce_price($product->get_price());
if ( $product->max_variation_price && $product->max_variation_price !== $product->min_variation_price ) {
$price .= '<span class="to"> ' . _x('to', 'max_price', 'woocommerce') . ' </span>';

$price .= woocommerce_price($product->max_variation_price);
}

return $price;
}

source: https://gist.github.com/mikejolley/1600117

share|improve this answer
add comment

Stumbled upon this thread looking for the same solution for Grouped products. Eventually wound up with the code below... so I'm posting it if it helps others. This will not work for variable products, just grouped. Figured this would be relevant since grouped/variable products are fairly similar and I thought others might also stumble upon this thread. You could probably clean up the span some but this is the quick and dirty version that got me going!

/*** Returns Price Range for Grouped Products**/
function wc_grouped_price_html( $price, $product ) {
$all_prices = array();

foreach ( $product->get_children() as $child_id ) {
    $all_prices[] = get_post_meta( $child_id, '_price', true );
}

if ( ! empty( $all_prices ) ) {
    $max_price = max( $all_prices );
    $min_price = min( $all_prices );
} else {
    $max_price = '';
    $min_price = '';
}

$price = '<span class="from">' . _x('From: ', 'min_price', 'woocommerce') . woocommerce_price( $min_price ) .  _x(' to ', 'max_price', 'woocommerce') . ' </span>' . woocommerce_price( $max_price );

return $price;
}
add_filter( 'woocommerce_grouped_price_html', 'wc_grouped_price_html', 10, 2 );
share|improve this answer
add comment

Woocommerce gives you the option to create variable products http://wcdocs.woothemes.com/user-guide/product-variations/

share|improve this answer
    
You misunderstand. I can do this just fine. I simply want to display "from (lowest cost) to (highest cost)" –  Btuman Oct 22 '12 at 5:06
    
@mirage this answer would become useless if woothemes changed their URL, a link answer is thus not an appropriate answer. Extract the relevant details from the page at the other end and incorporate them into an answer that can be understood by itself –  Tom J Nowell Mar 25 '13 at 13:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.