I am trying to access the price of a product for a selected product, so I can use it in my PHP code to do some calculations. I found code that only works partially. Only the price of the first variable product is displayed in the code. When I change the value from 0 to 1 in my line of code, it displays the price of the second option. $ availablevariations [0] ['variation_id']. I am trying to get the current price of a product based on any option selected from the drop-down list. Here is the code I'm using that doesn't work the way I would like to
global $product;
echo $saleprice = getpostmeta( gettheID(), '_price', true);
$regular_price = get_post_meta( get_the_ID(), '_regular_price', true);
if ($regular_price == ""){
$available_variations = $product->get_available_variations();
$variation_id=$available_variations[0]['variation_id'];
$variable_product1= new WC_Product_Variation( $variation_id );
$regular_price = $variable_product1 ->regular_price;
}
echo "<br> $regular_price ---This is the price I am trying to fix "
, , , , http://www.emotionadv.it/shop/volantini/volantino/, , .
, .