Skip to content

Instantly share code, notes, and snippets.

@grola
Last active January 22, 2018 10:58
Show Gist options
  • Save grola/482f1b8db6589922495b88d1e0f7deb7 to your computer and use it in GitHub Desktop.
Save grola/482f1b8db6589922495b88d1e0f7deb7 to your computer and use it in GitHub Desktop.
Display WooCommerce variable product price
add_filter( 'woocommerce_variable_price_html', 'studiowp_woocommerce_variable_price_html', 10, 2 );
function studiowp_woocommerce_variable_price_html( $price, $product ) {
if ( !is_singular( 'product' ) ) {
$prices = $product->get_variation_prices( true );
if ( empty( $prices['price'] ) ) {
$price = apply_filters( 'woocommerce_variable_empty_price_html', '', $this );
} else {
$prefix = 'From ';
$suffix = '';
$min_price = current( $prices['price'] );
$max_price = end( $prices['price'] );
$min_reg_price = current( $prices['regular_price'] );
$max_reg_price = end( $prices['regular_price'] );
$price = wc_price( $min_price );
$price = $prefix . $price . $suffix;
}
}
return $price;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment