Yankee
Yankee

Reputation: 21

Woocommerce Subtotal Only Numbers

I'm trying to get the float value from WooCommerce's cart

don't want to parse this function: $woocommerce->cart->get_cart_subtotal();

is there any way to get clean subtotal from the woocommerce's cart?

it suppose to be really simple, but i'm stuck :)

Upvotes: 2

Views: 1526

Answers (1)

helgatheviking
helgatheviking

Reputation: 26319

Borrowing from the cart class's get_cart_subtotal() method, I believe you could do something like:

if ( WC()->cart->tax_display_cart == 'excl' ) {

    $cart_subtotal = WC()->cart->subtotal_ex_tax;

} else {

    $cart_subtotal = WC()->cart->subtotal;

}

This assumes that you aren't doing compounded tax. The unformatted subtotals seem to be stored as class variables.

Upvotes: 2

Related Questions