php - How to get the price of variable product using variation ID? -


i have variation id of product. there way price of particular variation id.

i tried below code.

$variation_id = 12312; $price = get_post_meta($variation_id, '_regular_price', true); 

you code not display correct price if have set sale price product should use _price key that.

here code workout you.

$variation_id = '12312'; $price = get_post_meta($variation_id, '_price', true); 

or

$variation_id = '12312'; $variable_product = wc_get_product($variation_id); //$regular_price = $variable_product->regular_price; //$sale_price = $variable_product->sale_price; $price = $variable_product->price; 

please note: you can use of above given method i'll recommend use last one, because if woocommerce change metakey first code snippet not work 2nd 1 work.

hope helps!


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -