I know how to get cart totals. Fees and discounts are included in the calculation.
// Get cart subtotal & shipping total & fees & discounts
$subtotal = WC()->cart->subtotal;
$shipping_total = WC()->cart->get_shipping_total();
$fees = WC()->cart->get_fee_total();
$discount_excl_tax_total = WC()->cart->get_cart_discount_total();
$discount_tax_total = WC()->cart->get_cart_discount_tax_total();
$discount_total = $discount_excl_tax_total + $discount_tax_total;
// Cart Total
$cart_total = $subtotal + $shipping_total + $fees - $discount_total;
I need to get order totals also. I have a problem getting order discounts and fees.
function filter_woocommerce_get_order_item_totals( $order ) {
// Get order subtotal & shipping total & fees & discounts
$order_subtotal = $order->get_subtotal();
$order_shipping_total = $order->get_shipping_total();
$order_fees = ...
$order_discounts = ...
// Order Total
$order_total = $order_subtotal + $order_shipping_total + $order_fees - $order_discounts;
Order totals will be displayed on the order-received / thank-you page.
How can I get order fees and discount amounts for order totals calculation?
Below code does not seem to be the right answer:
$order_fees = $order->get_fees();
$order_discounts = $order->get_discount_total();