Subtotal cart variable php WooCommerce

Cedric De Clercq picture Cedric De Clercq · Jun 6, 2016 · Viewed 21.4k times · Source

Does anyone know what $variable to use in php to get the subtotal of the cart?
Subtotal = total value of cart BEFORE discount or taxes.

It would help me a lot. I want to add an extra fee if the subtotal is above 250 euro.

Thanks in advance.

Answer

LoicTheAztec picture LoicTheAztec · Jun 6, 2016

There is multiple ways to get cart subtotal:

  1. With global $woocommerce; variable (the old way-:

    global $woocommerce;
    $woocommerce->cart->subtotal; // or $woocommerce->cart->get_cart_subtotal()

  2. Without global $woocommerce; variable using simply WC() (nowadays):

    WC()->cart->subtotal // Or WC()->cart->get_cart_subtotal()

References: