Php 在Woocommerce 3中获取产品价格
我试图在我做的函数中得到没有货币的价格Php 在Woocommerce 3中获取产品价格,php,wordpress,woocommerce,hook-woocommerce,price,Php,Wordpress,Woocommerce,Hook Woocommerce,Price,我试图在我做的函数中得到没有货币的价格 function add_price_widget() { global $woocommerce; $product = new WC_Product(get_the_ID()); $thePrice = $product->get_price_html(); echo thePrice; } 显示:100kr 如何让它只给我价格100您可以使用只返回数字(不带点或符号)的函数get\u price 我刚刚在我的
function add_price_widget()
{
global $woocommerce;
$product = new WC_Product(get_the_ID());
$thePrice = $product->get_price_html();
echo thePrice;
}
显示:100kr
如何让它只给我价格
100
您可以使用只返回数字(不带点或符号)的函数get\u price
我刚刚在我的网站上测试了它,它工作了。所以它也应该对你有用
@Syntax\u Error所说的是正确的,您必须使用
,还提供了一个包装器函数
对于WC\u产品
class
因此,您的函数将如下所示:
function add_price_widget()
{
$product = wc_get_product(get_the_ID());
$thePrice = $product->get_price(); //will give raw price
echo $thePrice;
}
希望这有帮助 woocommerce 4.5.1-这已经发布了一个问题:我刚刚检查了woocommerce 4.5.1,没有发现任何错误。请指定您遇到的问题。未捕获错误:调用未定义的方法Automatic\WooCommerce\Admin\Overrides\Order::get_price()@AshwaniShukla:如果您选中此链接,我认为您遇到的问题是出于其他原因。
function add_price_widget()
{
$product = wc_get_product(get_the_ID());
$thePrice = $product->get_price(); //will give raw price
echo $thePrice;
}