Skip to content

@mikejolley /gist:1600117
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
WooCommerce - Show min - max prices for variations, rather than the min price only
/**
* 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;
}
@spylaw

Is there any way to display a specific variation price instead of the min/max price? For instance I have three variations attached to each product, could I specify one to display?

@morgyface

Hello Mike Jolley. I'm terrible at coding. I need your help, though not too much of it as I suspect it will be easy for your powerful brain.

All I want to do is display ONLY the max_variable_price. Can this filter be amended to do that? I was going to use CSS to display:none using this exact filter but both the min and max values have the same class.

I'd be over the moon if you could help.

@mikejolley
Owner

@morgyface you just need the:

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

part then. Replace lines 10-18 within the function.

@thfmartin

@mikejolley

If I do as suggested, it removes the option to select between different variables (in my case different price options) on the product. Do you have any suggestion to fix that?

Thanks

@angryoaf

Very useful but doesn't work if product has sale price.

@suzgala

Hi. What if you want to remove the "From" option on the product page all together?

@persianturtle

Yes, I am also wondering where the "From" is being generated from. Of course, we can always use CSS to hide it, but you would think it would be fairly easy to find the PHP file generating it and remove it. I have search for hours and with no luck!

@persianturtle

By the way, excellent work!

@specitechs

Hi, Mike,

I'm wondering if this code will help me at all
I've added postage options in my variables, so the price shows as from Min variable price.
is there any way to make it show a specific variable e.g. if you look at this shop page :
http://www.buyflowersnow.com.au/product/designer-choice-arrangements/
the price without any extras, or postage is $75, this shows if you select 'no thank you' for the extras, but not initially.
i was hoping to keep the postage options there as woocommerce isn't being very friendly with displaying them on checkout. my only option at the moment is to remove them.

@mannwd

@angryoaf If you want it to do both non-sale and sale items, add a second add_filter() with this:

add_filter('woocommerce_variable_sale_price_html', 'custom_variation_price', 10, 2);

@AncaIO

Great snippet :) It was very helpful in getting the "From: min_price" back after 2.1.1. Do you happen to have a similar solution for Product Bundles?

@adamxwr

HI works for me however on variable products it has somehow hidden my exc. VAT and inc. VAT text?
I add the exc. VAT and inc. VAT text via the tax tab in woocommerce settings under price display suffix: code below:
exc. VAT | {price_including_tax} inc. VAT

Any ideas? really need this to show!

@YogY11

Same issue here. how to show the "Price display suffix" set in the Woocommerce settings?

@leoui

Awesome! Very helpful.. thanks Mike!

@ipuiuna

Someone know how to show the price of variable products even if they have the same price?
Here one with differents prices (make any combination): http://www.armarinhospolo.com.br/catalogo/fitas-de-cetim/fita-de-cetim-numero-05/
And one who have the same price for all variations (this is the one who i need to show the price): http://www.armarinhospolo.com.br/catalogo/linhas/linha-resistente-5000-jd/

(sorry for my english)

@donsokoli

Code is working perfectly! Thanks a ton!

Just a quick question, is there an easy way to show From Price?
Like: Fra 99,95 Kr.

Fra = From in Danish.

@Veesibility

To only show min. price including tax, Replace lines 10-18 within the function by

$price .= woocommerce_price($product->get_price_including_tax());

@deryan12

@donsokoli is it possible by adding a ':before' selector with css. e.g:

.price del:before{
content: "Fra";
}

with that code on your price, is it possible to show the label before the price ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.