On single product page of variable product, when I change different variation from the dropdown, I want to show the price from another custom field instead of default variation price (which field I already created in Dashboard). But, I didn't find a way to show the price on product page.
Here's my code:
add_filter('woocommerce_product_variation_get_regular_price', 'custom_price', 99, 2 );
add_filter('woocommerce_product_variation_get_price', 'custom_price', 99, 2 );
function custom_price( $price, $product )
{
return $price;
}
Inside the function custom_price
, if I get the variation id, I could do something like this:
function custom_price( $price, $product )
{
$variation_id = ???
return get_post_meta( $variation_id, 'custom_field', true );
}
How can I get variation id inside this function? Thanks in advance.