Razvan Cuceu
Razvan Cuceu

Reputation: 577

Woocommerce get product price by id in simple page

I need to a php file that can show a product's price by id. I have tried doing this with this code in a "price.php" file with this content:

I'm sure that something that links this with wp is missing, but what?

<?php
$price = get_post_meta( '225', '_regular_price', true);
echo $price;
?>

Upvotes: 1

Views: 16877

Answers (1)

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21691

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

$product = new WC_Product($product_id);

After Creating Object you can run any of WooCommerce's product methods.

$product->get_regular_price();
$product->get_sale_price();
$product->get_price();

Upvotes: 4

Related Questions