Last week I did a tutorial that showed you how to change your WooCommerce 2.1 Variation prices from the new range format to the old WooCommerce 2.0 From: format, that tutorial however only included changing the prices of variable products.
The following tutorial shows you how to modify the Grouped Product prices that also uses the new range format in WooCommerce 2.1 to the WooCommerce 2.0 From: format.
To change the pricing format for your WooCommerce grouped products add the code below 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
<?php | |
// Place in your theme's functions.php file | |
// Revert grouped product prices to WooCommerce 2.0 format | |
add_filter( 'woocommerce_grouped_price_html', 'wc_wc20_grouped_price_format', 10, 2 ); | |
function wc_wc20_grouped_price_format( $price, $product ) { | |
$tax_display_mode = get_option( 'woocommerce_tax_display_shop' ); | |
$child_prices = array(); | |
foreach ( $product->get_children() as $child_id ) { | |
$child_prices[] = get_post_meta( $child_id, '_price', true ); | |
} | |
$child_prices = array_unique( $child_prices ); | |
$get_price_method = 'get_price_' . $tax_display_mode . 'uding_tax'; | |
if ( ! empty( $child_prices ) ) { | |
$min_price = min( $child_prices ); | |
$max_price = max( $child_prices ); | |
} else { | |
$min_price = ''; | |
$max_price = ''; | |
} | |
if ( $min_price == $max_price ) { | |
$display_price = wc_price( $product->$get_price_method( 1, $min_price ) ); | |
} else { | |
$from = wc_price( $product->$get_price_method( 1, $min_price ) ); | |
$display_price = sprintf( __( 'From: %1$s', 'woocommerce' ), $from ); | |
} | |
return $display_price; | |
} |
That works great thx. Got a blank website at first entry of this code but then saw the ‘?>’ needed to be added to the end and all was good.
Thankyou!
Hi Gerhard,
Just what I was looking for, thanks. But on my site the from is inside the price bubble and the price outside,
Can the price be inside also ? seems like a spacing problem ?
Thanks
I added this to what i believe was the functions.php file and its completely wiped my site including any editors etc, i can no longer go in and remove the code. What do i do?
If i go onto the wp-admin section its just a white screen 🙁
Scratch my previous post, after a few refreshes it now display correct.
I am having problems translating the from price word FROM to other languages. Does this hack disable translation in any way?
Thanks
Kaj
Hi thanks for the code… could you advise on having the price inc vat and exc vat to display on variations pages? think part of the code strips this out? thanks
Hi Thanks for the code… it is returning the price as from: £1.00. Would there be a way to display the price as from: £1.00 exc VAT | £1.20 inc VAT? Please can you help as im desperate to get this working. Must just be a small tweek to the code but i cant figure it out! thanks
Hello. Your script gave me an idea and I am trying to implement it for using grouped products, with some modifications, in a project to sell music, But i have a problem. In my grouped products, in this case an album, there is always a free song, with price 0. The songs are also sold individually. The song with price 0 is for free download. Then, when i grouped the songs in an album (grouped products) including the free song, because of this song (price 0), the price is not shown on the grouped product page. When not included the free song everything is ok, even managed to make the price is the sum of all the prices, and that for my case is well. But I have tried to make the adjustments that I think are necessary to resolve this problem of the price 0 and i have not succeeded in finding the solution. I am not expert programmer and don’t know all the parameters and functions of Woocommerce (and Idon’t speak english, this is Google translator). Can you help me to resolve this problem, please? Thank you in advance.
0 Pingbacks
Categories
Top Posts & Pages
Instagram
No Instagram images were found.
Get Email Notifications