Display coupons codes and discount amounts used on an order in WooCommerce

I am trying to display the amount of the coupon used on an order with the following: foreach( $order->get_coupons() as $item ){ $code = $item->get_code(); $coupon = new WC_Coupon($code); $html .= '<tr> <td>' . ucfirst( $code ) . '</td> <td>' . $coupon->get_amount() . '</td> </tr>'; } But instead, it is displaying the balance left of each coupon code used. How can I display the coupons discount amounts used on an order in WooCommerce?

Comment (1)

Jese Leos

August 23, 2024

Verified user

To get the coupon data from the order object, try instead the following: $html = ''; // Initializing (optional) // Loop through coupon items for the current order foreach( $order->get_items('coupon') as $item ){ // Coupon code $coupon_code = $item->get_code(); $coupon_discount = $item->get_discount() + $item->get_discount_tax(); $html .= '<tr> <td>' . ucfirst( $coupon_code ) . '</td> <td>' . wc_price( $coupon_discount ) . '</td> </tr>'; } Here we use WC_Order_Item_Coupon available methods. It should work.

You’ll be in good company