Get woocommerce product price on php page

Johnny97 picture Johnny97 · Jul 28, 2016 · Viewed 14.5k times · Source

I've tried it a long long time to get the price from a specific product on a php file but I cant find a solution. I've tried it with woocommerce shortcodes but I always get the full product in my div and not the price.

Does anybody know a solution?

Thank you so much!

Answer

helgatheviking picture helgatheviking · Jul 28, 2016

Create a product object. Then you can use any of WooCommerce's product class methods, such as get_price_html()

$product_id = 99;
$product = wc_get_product( $product_id );
echo $product->get_price_html();