2017-04-20 118 views
2

我试图在没有货币的情况下得到我所做的功能。获得产品价格没有货币

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

    echo thePrice; 
} 

显示:100kr

我如何得到它只是给我的价格100

回答

2

说过什么@Syntax_Error是正确的,你必须使用 get_price(),WooCOmmerce也为WC_Product类提供包装函数 wc_get_product()

所以你的函数会是这个样子:

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

希望这有助于!

1

您可以只使用功能get_price仅返回数(不包含句点或符号)

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

我刚刚在我的网站测试它,它的工作。所以它也适用于你。