Asked
Active
Viewed 1.1k times
0

sunilsingh
- 503
- 1
- 5
- 9
-
you can use this $woocommerce->cart->get_cart_total(); to get total on cart page. – Husain Ahmed Sep 16 '16 at 10:49
-
It will gives subtotal price not total price. I have mentioned in attachment for total. – sunilsingh Sep 19 '16 at 04:19
-
actually when i add some custom tax with order on checkout page without page refresh using ajax, yes i do like subtotal $50 and custom tax $5 then total would be $15, but without page refresh how can i get total price for update total. – sunilsingh Sep 19 '16 at 04:25
2 Answers
3
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.
-
1It will gives subtotal price not total price. I have mentioned in attachment for total. – sunilsingh Sep 19 '16 at 04:26
0
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.
According to LoicTheAztec
add_action( 'woocommerce_checkout_create_order', 'get_total_cost', 20, 1 );
function get_total_cost($order){
$total = $order->get_total();
}

Web Design
- 77
- 2
- 19