Reputation: 577
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
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