In the functions file I have added a filter hook to add a custom label before the variation product "min" price.
How can I get the label in the same line as the price?
See my code and the screenshot below:
add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
function wc_wc20_variation_price_format( $price, $product ) {
$min_price = $product->get_variation_price( 'min', true );
$price = sprintf( __( 'From%1$s', 'woocommerce' ), wc_price( $min_price ) );
return $price;
}
Since WooCommerce 3,
woocommerce_variable_sale_price_html
hook is deprecated and not anymore useful. If you don't care about "min" sale price (when the min price is on sale), you can use this:Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works on WooCommerce 3+. You will get something like this:
If you care about "min" sale price (when the min price is on sale), and you want to display both prices, you should use this code instead:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works on WooCommerce 3+. You will get something like this: