Get woocommerce carts total amount

Try this:

WC()->cart->cart_contents_total

The function get_cart_total uses wc_price function thas converts cart_contents_total to currency.


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.


You need to call the global variable to ensure that it gets the correct values.

If you add

 global $woocommerce;

just before

 $amount2 = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_total() ) );

that should solve your problem.