5

i want put an pixel for tracking my orders for affiliate.

I must get my total order after discount, so without Tax and Shipping cost.

I've make something like this but it's display 0 .

<?php echo $woocommerce->cart->get_total_ex_tax(); ?>

It's maybe because it's display currency symbol.

bytecode77
  • 14,163
  • 30
  • 110
  • 141
Clément Houde
  • 666
  • 1
  • 7
  • 5
  • Why isn't `0` an acceptable return value? It sounds like the order total is actually `0`, after discounts, and before shipping and taxes. – rnevius Nov 20 '15 at 14:29
  • Hello, thanks for your reply, because that can matter the amount of my order my return value is always 0. So It is a mistake. – Clément Houde Nov 20 '15 at 15:50

5 Answers5

5

This it the cart total without tax and shipping.

$cart_value = number_format( (float) $order->get_total() - $order->get_total_tax() - $order->get_total_shipping() - $order->get_shipping_tax(), wc_get_price_decimals(), '.', '' );
Frits
  • 7,341
  • 10
  • 42
  • 60
Vmadmax
  • 94
  • 3
  • 8
4

Vdadmax's answer is almost correct. If tax is applied on shipping, then it's deducted twice in his case (the total shipping cost including tax is deducted and after that, shipping sales tax is deducted again), leaving you with a final total that is too low.

This gives you the correct total with all sales tax and shipping deducted:

$cart_value = number_format( (float) $order->get_total() - $order->get_total_tax() - $order->get_total_shipping(), wc_get_price_decimals(), '.', '' );

I can't comment yet, hence the reason why I am adding this as an answer instead.

lelas
  • 61
  • 3
2

This helps me to get the total amount without tax.

WC()->cart->subtotal_ex_tax
Shiva Aryal
  • 141
  • 1
  • 7
1

Have you tried?

$cart_value = $order->get_total_tax() - $order->get_total();
Alexandru R
  • 8,560
  • 16
  • 64
  • 98
0
get_woocommerce_totals()['cart_subtotal']['value']
CDspace
  • 2,639
  • 18
  • 30
  • 36
Juergen Schulze
  • 1,515
  • 21
  • 29