Instantly share code, notes, and snippets.

@grola /functions.php
Last active Jan 22, 2018

Embed
What would you like to do?
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