With WooCommerce 2.1 just being released a couple of days ago, a lot of users may have noticed a couple of big changes to the plugin, like a refined settings section and the introduction of an all new REST API.
The aim with each major WooCommerce release is to simplify and make it faster and more scalable, and with WooCommerce 2.1 this meant that a lot of the setting that was rarely uses was removed and a few formatting changes was made based on customer feedback.
One of the formatting changes that was made was to remove the “From: $x” price formatting of variation products in favor of a range ie “$x – $y”. This new range format for variable product may not appeal to everyone and that is where the following snippet comes into play.
The code snippet will change the new range price format back to the “From:” price format that users are accustomed to in WooCommerce 2.0.
To revert your WooCommerce variation prices back to the “From:” price format add the following code to your theme’s functions.php file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use WC 2.0 variable price format, now include sale price strikeout | |
* | |
* @param string $price | |
* @param object $product | |
* @return string | |
*/ | |
function wc_wc20_variation_price_format( $price, $product ) { | |
// Main Price | |
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) ); | |
$price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); | |
// Sale Price | |
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) ); | |
sort( $prices ); | |
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); | |
if ( $price !== $saleprice ) { | |
$price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>'; | |
} | |
return $price; | |
} | |
add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 ); | |
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 ); |
Thanxs for this hack!
Hey how about removing the price range from the products page entirely?
Hi Tom, for that you can use the following code
add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
function wc_wc20_variation_price_format( $price, $product ) {
return '';
}
Hello Gerhard,
Thanks for this wonderful solution. Works like magic.. 🙂
I have question, how can I show “from: $min_price” to my shop page and homepage? Right now, what is showing is the price range ($min_price – $max_price). I would like to show “from: $min_price” just like the individual product page itself.
Thanks ahead! 🙂
-Ray
many many thanks bro.
Maybe you have an idea how I can fix something that broke with Woo 2.1.1.
Before Woo 2.1.1, each product price used to have a short line of text after the dollar amount. Instead of just “$35”, the product page would say “$35 per 750ml bottle”.
Now with Woo 2.1.1, it just says $35 again, with no way to qualify what the $35 buys.
Where can I add that line of text after the price of each item (on that same line, in that same font) to ensure it’s understood that the price is per 750ml bottle? I can’t find an associated php file to modify.
Woo support linked me to this page in hopes of finding a fix. Big thanks in advance.
Hi Jason,
I just responded to your support ticket regarding this 🙂
Any chance you would share this fix…. same issues here.
This code works great except on my grouped products….. i’m guessing something like this will need to be added??
add_filter( ‘woocommerce_grouped_price_html’);
Hi Mooke
Yes the code above will only work for variations, I will do a tutorial later today to revert grouped product prices as well.
Hi Mooke, please see http://gerhardpotgieter.com/2014/02/24/woocommerce-2-1-grouped-prices-revert-to-woocommerce-2-0-format/
Hi!
Do you know how to add this to “Composite Products” extension, cause some how this change in my functions.php only reflects the Variations products and not those setup up using the extension Composite Products. It would be great to have that back as it was…
I don’t know which filter it uses to present prices though.
Hi Alex
Give the following a try and see if that works for you http://gerhardpotgieter.com/2014/02/24/woocommerce-2-1-grouped-prices-revert-to-woocommerce-2-0-format/
Hello,
Any idea on how to translate this? I’ve managed to get the From, but need it in Dutch. Already checked localisation files of WooCommerce, it’s translated correctly, and I’m unable to find “From” in my theme localisation files.
Thanks!
Stefan
Ok, I should ask so fast. Fixed it by just changing it in your code.
Thanks for your code snippet though. Took me a while to find a good solution.
Worked like a charm. Thanks!
Hi Gerhard,
thank you – that helped a lot.
Unfortunately I have one little problem with your code and it would be awesome if you can help me out.
Somehow your code will generate a sale price for a product on the category page even though there isn’t any sale for this specific product. It will just display two times the same price and the first one is crossed out.
Do you know how to fix this?
Thank you and greetings from Germany,
Richard
Hey Richard! Were you able to figure this problem out? I am experiencing the same thing
Fantastic – it is not quite what I am looking for but I hope you can help.
For a grouped product I would like to display ONLY the max price – is this possible ?
Best,
Flemming
Hi, I have tried your code and still nothing is working. Any other ideas?
Do you know how to change the price on the single product page for variation products?
I want to add text after the selected variation price but dont know or cant find the file in which to adapt it to my needs. Can you help?
Hi Gerhard,
Thanks for the hack, however I’d like to do things a bit differently.
On my product page it displays the price range and also the dynamic price of the product.
Would it be possible to replace the price range with the dynamic price ?
If yes, will the products with no price variables still have their price displayed ?
Thanks a lot for your help 😉
thank you so much buddy ! i was pulling my head on the walls from last 1 day to find the solution. well you r great ! i just edited your code & used following code which dispays ‘From : max’ (max price),
add_filter(
‘woocommerce_variable_sale_price_ht
ml’,
‘wc_wc20_variation_price_format’,
10, 2 );
add_filter(
‘woocommerce_variable_price_html’,
‘wc_wc20_variation_price_format’,
10, 2 );
function
wc_wc20_variation_price_format(
$price, $product ) {
// Main Price
$prices = array( $product-
>get_variation_price( ‘max’, true
), $product->get_variation_price(
‘max’, true ) );
$price = $prices[0] !==
$prices[1] ? sprintf( __( ‘%1$s’,
‘woocommerce’ ), wc_price( $prices
[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( $product-
>get_variation_regular_price(
‘max’, true ), $product-
>get_variation_regular_price(
‘max’, true ) );
sort( $prices );
$saleprice = $prices[0] !==
$prices[1] ? sprintf( __( ‘From:
%1$s’, ‘woocommerce’ ), wc_price(
$prices[0] ) ) : wc_price( $prices
[0] );
if ( $price !== $saleprice
) {
$price = ‘
‘ .$saleprice . ‘ ‘ .
$price . ”;
}
return $price;
}
Hi Gerhard,
I tried with composite products and does not work.
Maybe should I change woocommerce_grouped_price_html with some other string?
Tried with woocommerce_composite_price_html but nothing..
Thank you
Alex
Hi !
I put this code and it works so thank you !
BUT i now got a problem with the simple products… When i put a promotion the regular price between the
doesn’t appear. How can i please fix it ???Thank you !!
In fact my problem is the following : http://www.serenis-bains.fr/produit/baignoire-a-porte-constance
I got the same price strikedout. How can i solve this problem please ??
Hi Nico,
how did you fix your problem ?
Hi thanks for the code…
I added inc vat and exc vat to my pages via the the woo settings > tax > price suffix. This displays exc VAT and exc. VAT text after my prices which is fine. However when using your code my inc and exc VAT suffix disappears on variable product pages? I really need to show price as:
From: £1.00 inc VAT | £1.20 exc. VAT
I think your code strips something out as it will display ok on simple products?
Any ideas how to fix? Getting desperate now!
thanks
where the text was “tax included”?
like to do:
Before -> 13.50 $ -57.00 $ (incl. TAX)
Now -> From: $ 13.50 (incl. TAX)
Thank you
Thanks a lot, Gerhard! Exactly what I needed.
Hi Gerard,
Would you know how to switch the dash for a stroke for the variations prices ?
$140 – $240
for
$140 / $240
thanks!
Thanks for sharing, exactly what I was looking for and works a treat on both the grid and single page.
I have a question? How do I stop getting notification of this thread?
This code broke my website? Now getting a parse error – maybe I put it in wrong? Any ideas?
did you fix it? I put it into mine also and the whole sites gone and i have no idea how to get it back
Hello, after doing this I had a fatal error…..
Parse error: syntax error, unexpected ‘<' in C:xamppappswordpresshtdocswp-contentthemesfruitfulfunctions.php on line 1583
HELP PLEASE.
Solved!!! thank´s
Hello Gerhard
I am using WooCommerce Bookings so have a bookable product and none of these hooks are working for me.
Ideally I would like to remove the From R… and then after the Price add the words: Per Session.
Can you help me out please or point me in the right direction.
Many Thanks
Dale
Hi
I found part of my answer here > https://support.woothemes.com/hc/en-us/articles/202974056-How-to-remove-From-text
can you please assist me with adding the text after the price.
Hi Gerhard,
I tried adding the code for removing the price range completely, and it broke the site. I’m obviously not doing it right. I don’t know anything about PHP, but am not afraid of editing code, as long as I know exactly where to put it. Putting in the code with or without the “?php” and “}” tags didn’t work. Please help, and thanks in advance.
Hi Gerhard,
this code seems only to work with variations. My problem is related to bookings and bookable products. How can I add text after the price? My client offers 3- and 6-months bundles and I need the words “per month” after the price. Have you any idea how to achieve that?
Thanks so much in advance
Dan
Thanks for sharing the code, I’ve been struggling with how to get a from price since some of my variations go from £60-£6000 on the the same product which was putting people off.
Your a life saver thanks
Andy
Hi,
Can you update the code? Because it is not working with woocommerce 2.3.3
Regards
My bad, the code still works..
WOW – I INPUT THE CODE AND THIS HAS CRASHED MY SIRE AND ITS JUST ALL GONE WHITE!
Please help! what do i do now???
If you get a white screen try not to paste the opening tags, your file most likely already have this.
Is it posible to show the lowest “sale” price if it exists?
And then don’t show the standard price?
http://www.esportclothing.com/product-category/team-store/
anyone?
Hi, i have tried everything, i used this code on funtions.php and still does not working!
I don’t know what esle to do.
0 Pingbacks
Categories
Top Posts & Pages
Instagram
No Instagram images were found.
Get Email Notifications