I am trying to apply a discount to a carts total price, but I can only do it to the item base price and not the over all price. I Googled and came across this post in the w
As of late 2018, the best way is to use get_cart_contents_total()
. This is the total of items in the cart after discounts.
WC()->cart->get_cart_contents_total(); // Float
Other methods are available for more specific needs, just have a look at the docs.
WC()->cart->subtotal;
this function use for get total without currency
WC()->cart->get_total();
this function use for get total with currency
This also work nicelly.
WC()->cart->total
Function get_cart_contents_total() gives the total of items in the cart, but after discounts. Depending on the tax settings you might have to add taxes. Something lie this:
$cart_total_price = wc_prices_include_tax() ? WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax() : WC()->cart->get_cart_contents_total();
This works perfectly and removes currency symbol:
$woocommerce->cart->total;
The following code outputs formatted price with currency
wc_price( WC()->cart->cart_contents_total); // Output example $118,000