I have written this to extract the product variation prices
global $product;
if ( $product->is_type('variable') ) {
function get_product_variation_price($variation_id) {
global $woocommerce;
$product = new WC_Product_Variation($variation_id);
return $product->get_price_html();
}
$product_variations = $product->get_available_variations();
$arr_variations_id = array();
foreach ($product_variations as $variation) {
$product_variation_id = $variation['variation_id'];
$product_price = get_product_variation_price($product_variation_id);
}
$amount = get_product_variation_price($product_variation_id);
} else {
$amount = str_replace(".", ",", $product->get_price());
}
What I am trying to achieve is that if the product is a variable product, the amount variable changes to what currently selected variants set price is, however, this will always get me the first variants price. How can I achieve that?