I want to display the cost of the product after a discount coupon on the invoice. I have the following code, but it displays only base price, not the cost after coupon code:
add_filter( 'wpo_wcpdf_woocommerce_totals', 'wpo_wcpdf_woocommerce_totals_custom', 10, 2 );
function wpo_wcpdf_woocommerce_totals_custom( $totals, $order ) {
$totals = array(
'subtotal' => array(
'label' => __('Subtotal', 'wpo_wcpdf'),
'value' => $order->get_subtotal_to_display(),
),
);
return $totals;
}
I tred to change $totals to $discount, but it didn't work.
Your actual code is just removing all totals, displaying the subtotal only. Please try the following hooked function, that will display the discounted subtotal after the discount amount:
Code goes in function.php file of your active child theme (or theme).
Tested and works. It should work for you too.