Get the product price in Woocommerce 3

Oscar vs picture Oscar vs · Apr 20, 2017 · Viewed 8.4k times · Source

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

Displays: 100kr

How do I get it to just give me the price 100

Answer

Raunak Gupta picture Raunak Gupta · Apr 21, 2017

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

Hope this helps!