2016-07-28 92 views
3

我试了很长时间才从php文件上的特定产品获得价格,但我找不到解决方案。我试过用woocommerce简码,但我总是得到完整的产品在我的div而不是价格。在php页面上获取woocommerce产品价格

有没有人知道解决方案?

非常感谢!

<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>

回答

8

创建产品对象。然后,您可以使用WooCommerce的任何产品分类方法,例如get_price_html()

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

非常感谢! – Johnny97

相关问题