Display only one price for grouped products – WooCommerce

This is just a handy little function to control what price is displayed for a range of products that have been grouped in WooCommerce. Often the grouped products all have different prices and by default WooCommerce will display a range such as £50 – 1000. Which is not ideal. This function allows you to display the maximum price.

[php]

/**
* Returns max price 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 );
} else {
$max_price = ”;
}

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

return $price;
}
add_filter( ‘woocommerce_grouped_price_html’, ‘wc_grouped_price_html’, 10, 2 );

[/php]

NB: This is not originally my code, but unfortunately I can no longer find the website that published it to reference it correctly.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s