在Woocommerce 3中获取产品价格 [英] Get the product price in Woocommerce 3

查看:230
本文介绍了在Woocommerce 3中获取产品价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过自己制作的函数获取不含货币的价格.

I'm trying to get price without currency in a function I made.

function add_price_widget()
{
    global $woocommerce;
    $product = new WC_Product(get_the_ID());
    $thePrice = $product->get_price_html();

    echo thePrice;
}

显示:100kr

如何获取价格给我100

推荐答案

@Syntax_Error所说的是正确的,您必须使用 get_price() ,WooCOmmerce还提供了包装函数 wc_get_product() 用于WC_Product类.

What @Syntax_Error had said is correct you have to use get_price(), WooCOmmerce also provide a wrapper function wc_get_product() for WC_Product class.

所以您的函数应如下所示:

So your function would look something like this:

function add_price_widget()
{
    $product = wc_get_product(get_the_ID());
    $thePrice = $product->get_price(); //will give raw price
    echo $thePrice;
}

希望这会有所帮助!

这篇关于在Woocommerce 3中获取产品价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆