Skip to content

Instantly share code, notes, and snippets.

@DanielSantoro
Created July 18, 2014 15:45
Show Gist options
  • Save DanielSantoro/1890d30f46024fbdb80b to your computer and use it in GitHub Desktop.
Save DanielSantoro/1890d30f46024fbdb80b to your computer and use it in GitHub Desktop.
Only display maximum price for WooCommerce variable products
/**
* Only display maximum price for WooCommerce variable products
**/
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
function custom_variation_price( $price, $product ) {
$price = '';
$price .= woocommerce_price($product->max_variation_price);
return $price;
}
@zngntr
Copy link

zngntr commented Sep 29, 2023

Here is the working code:

/**

  • Display the price of the highest priced variation for WooCommerce variable products
    **/
    add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);

function custom_variation_price( $price, $product ) {
// Get the highest priced variation
$highest_price = $product->get_variation_price('max');

 if ($highest_price > 0) {
     // Display the highest price
     $price = wc_price($highest_price);
 }

 return $price;

}

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