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.
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.
You must be logged in to post a comment.
There is multiple ways to get cart subtotal:
With
global $woocommerce;
variable (the old way-:global $woocommerce;
$woocommerce->cart->subtotal;
// or
$woocommerce->cart->get_cart_subtotal()
Without
global $woocommerce;
variable using simplyWC()
(nowadays):WC()->cart->subtotal
// Or
WC()->cart->get_cart_subtotal()
References:
WooCommerce wc_cart class
WooCommerce WC_Cart API Docs
I kept getting an incorrect subtotal (a little high, but could not determine why) using Loic’s code snippets.
I tried every similar variant and eventually found the following code:
Using this snippet above, I get precisely the amount expected which matches the actual subtotal displayed in the cart.
Now my ‘free shipping’ upsell calculation is working perfectly.