I want to get total price of cart in my woocommerce plugin.
I want to get it as a float number like so: 21.00 but I don\'t know how to get it. My code outputs weird
I have code like this and working perfect:
if ( ! WC()->cart->prices_include_tax ) {
$amount = WC()->cart->cart_contents_total;
} else {
$amount = WC()->cart->cart_contents_total + WC()->cart->tax_total;
}
good luck !
In 2020 with Woocommerce 4+
$total_cart = WC()->cart->get_displayed_subtotal(); // without taxs and shipping fees
echo $total_cart; // ex: 0.00
Just access the total
property directly, it's public:
global $woocommerce;
echo $woocommerce->cart->total;
global $woocommerce;
$amount = $woocommerce->cart->cart_contents_total+$woocommerce->cart->tax_total;
You can also convert $amount in float value as per your requirement.
Try this WC()->cart->cart_contents_total
global $woocommerce;
$woocommerce->cart->cart_contents_total (Cart total)
$woocommerce->cart->tax_total (tax total)
$woocommerce->cart->shipping_total (shipping total)