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
What @Syntax_Error had said is correct you have to use
get_price(), WooCOmmerce also provide a wrapper functionwc_get_product()forWC_Productclass.
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!
You can just use the function get_price that returns only the number (without dots or symbol)
function add_price_widget() {
 global $woocommerce;
 $product = new WC_Product(get_the_ID()); 
 $thePrice = $product->get_price();
 echo thePrice;
}
I just tested it in my site and it work. So it should work for you too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With