Reputation: 706
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.
Upvotes: 5
Views: 23133
Reputation: 1
global $woocommerce;
$total = $woocommerce->cart->get_subtotal();
$formatted_total = wc_price($total);
Upvotes: 0
Reputation: 409
This helps me to get the total amount without tax.
WC()->cart->subtotal_ex_tax();
Upvotes: 1
Reputation: 71
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.
Upvotes: 5
Reputation: 94
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(), '.', '' );
Upvotes: 5
Reputation: 8823
Have you tried?
$cart_value = $order->get_total_tax() - $order->get_total();
Upvotes: 1