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?

New contributor
Jamie Crafts is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • WooCommerce and other 3rd party plugin/theme dev support is off topic and not in this stacks scope. You should ask via their official support routes or in their groups and communities.
    – Tom J Nowell
    Jun 22 at 9:59


Browse other questions tagged or ask your own question.