Skip to content

Instantly share code, notes, and snippets.

@cobbman
Last active May 30, 2018 18:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cobbman/3895973 to your computer and use it in GitHub Desktop.
Save cobbman/3895973 to your computer and use it in GitHub Desktop.
WooCommerce - Show min - max prices for variations, rather than the min price only
/**
* This code should be added to functions.php of your theme
**/
//This changes the "From:" price on the products page to a Rent-Buy value instead.
// ***** It ALSO checks to see if the product is on sale, and displays the sale price instead of the top variable price
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
function custom_variation_price( $price, $product ) {
$price = '';
// Check if there's a min_variation_price. Gets the minimum value of the product variation and displays it as rent price (see class-wc-product.php under woocommerce/classes)
if ( !$product->min_variation_price || $product->min_variation_price !== $product->max_variation_price ) {
//Assign the rent price
$price .= '<span class="from">' . _x('Rent:', 'min_price', 'woocommerce') . ' </span>';
}
$price .= woocommerce_price($product->get_price()) . '<br />';
//check if the product is on sale, display sale price instead of max price
// if not on sale, display the max price as the buy price
if ( $product->max_variation_sale_price && $product->max_variation_price !== $product->max_variation_sale_price) {
$price .= '<span class="to"> ' . _x('Buy:', 'max_variation_sale_price', 'woocommerce') . ' </span>';
$price .= woocommerce_price($product->max_variation_sale_price);
} elseif ($product->max_variation_price && $product->max_variation_price !== $product->min_variation_price) {
$price .= '<span class="to"> ' . _x('Buy:', 'max_price', 'woocommerce') . ' </span>';
$price .= woocommerce_price($product->max_variation_price);
}
return $price;
}
@cobbman
Copy link
Author

cobbman commented Oct 16, 2012

I'm working on making this conditional, so that it will only do this if the product has the tag: rent.

@warmsunshine000
Copy link

Hello,
How are you?

My name is Warm.

Could you help me with one thing?

I have client's website now.

http://handilifesport.test.albers.dk/

Currently Variable Products Price Range is wrong showing now.

For example, http://handilifesport.test.albers.dk/en/product/single-superior-rio2016-boccia-ball/

There are some another issues in the site now.

Help me please.

Many thanks and Kind Regards.

Warm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment