If there are 2 discount coupons used, it shows the sum of 2 coupons in the Woocommerce order totals table, while I want to show the deducted cost of each coupon separately.
For example, 2 coupons are inserted, currently it shows:
- coupon : $100
I want to change this to:
-
coupon1(coupon code) : $50
-
coupon2(coupon code) : $50
Path from the WooCommerce template file: order-details.php
foreach ( $order->get_order_item_totals() as $key => $total ) {
?>
<tr>
<th scope="row"><?php echo esc_html( $total['label'] ); ?></th>
<td><?php echo ( 'payment_method' === $key ) ? esc_html( $total['value'] ) : wp_kses_post( $total['value'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
</tr>
<?php
}
Any advice on how to change this?
2
Answers
It is not necessary to add HTML table tags via the
woocommerce_get_order_item_totals
hook, since it concerns table rows.Next answer removes the default discount row and splits it over several rows with the desired details.
Functions used in this answer:
So you get:
Result:
Related: Add coupon names and percentage to WooCommerce view order details and email notifications