user6580560
user6580560

Reputation:

Get woocommerce product price on php page

I've tried a long time to get the price from a specific product on a php file but I can't 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?

<div class="package-header">
    <span class="packe-title bronze-title">Bronze</span>
</div>
<div class="price-container">
    <?php $price=get_post_meta( get_the_ID(), '_regular_price'); echo $price; ?>
</div>

Upvotes: 5

Views: 19427

Answers (1)

helgatheviking
helgatheviking

Reputation: 26319

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();

Upvotes: 11

Related Questions