Reputation: 499
How to get Woo-commerce order total on cart page.
Upvotes: 0
Views: 12161
Reputation: 105
As order total in checkout is variable, i.e. is sum of added tax or shipping costs, you can get it after the order is set. You can access it when place order button is clicked. By woocommerce_checkout_create_order
action hook.
add_action( 'woocommerce_checkout_create_order', 'get_total_cost', 20, 1 );
function get_total_cost($order){
$total = $order->get_total();
}
Upvotes: 0
Reputation: 11808
Use $cart
to access the cart object.
Use $cart_total
to access the cart total after all the calculations.
add_action("woocommerce_cart_contents", "get_cart");
function get_cart()
{
global $woocommerce;
// Will get you cart object
$cart = $woocommerce->cart;
// Will get you cart object
$cart_total = $woocommerce->cart->get_cart_total();
}
The cart total echoed here will be displayed above Cart table.
Refer to the WC_Cart class documentation for more help.
Upvotes: 3