I have the following code to display price once entering single product page.

   global $woocommerce;
   $product = new WC_Product(get_the_ID()); 
   echo $product->get_price_html(); //Shows the price

I have tried serval variation of this code, but they all either error or empty value.

Although <?php echo get_the_title() ?> does work.

What can be causing get_price_html() to echo empty value?

1 Answer 1


If you have the product's ID you can use that to create a product object:

$product= wc_get_product( $product_id );

Then from the object you can run any of WooCommerce's product methods.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.