Skip to content

Instantly share code, notes, and snippets.

@grola
Last active January 22, 2018 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grola/b7848fea13d2266b90f9ffbac1565a7b to your computer and use it in GitHub Desktop.
Save grola/b7848fea13d2266b90f9ffbac1565a7b to your computer and use it in GitHub Desktop.
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;
}
}
else {
$price = '';
}
return $price;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment