My variable products show two price sections, one is the price range for all the products and the other is the price for the chosen product if one is selected. But if the price for the products is the same it only shows one price.
What I want is when an option is selected if the price of the products ranges I want to replace the price range with the price of the selected variation. And if no option is selected I want the price range to show. I haven't been able to find the correct filter or hook for this, can you help?
Here is a couple images to show you what I am talking about;
Yagnesh Makwana's code could be used to make this functionality work but, I need to be able to get the price of the currently selected variation. Look in the if statement below $variation_price needs to be set equal to the current selected variation price;
add_filter( 'woocommerce_variable_sale_price_html', 'detect_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'detect_variation_price_format', 10, 2 );
function detect_variation_price_format( $price, $product ) {
// get min and max price of varaitions and store in $prices array
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
//if min and max price are not the same
if ($prices[0] !== $prices[1]) {
$variation_price = get selected variation price;
$price = sprintf( __( $variation_price, 'woocommerce') );
}
return $price;
}