Coupons not showing in WooCommerce admin orders list

3 weeks ago 22
ARTICLE AD BOX

I'm using code that displays a custom "Coupons" column with the name and description of the coupons used in the order.

add_action( 'manage_shop_order_posts_custom_column' , 'woo_display_customer_order_coupon_in_column_for_orders' ); function woo_customer_order_coupon_column_for_orders( $columns ) { $new_columns = array(); foreach ( $columns as $column_key => $column_label ) { if ( 'order_total' === $column_key ) { $new_columns['order_coupons'] = __('coupons', 'woocommerce'); } $new_columns[$column_key] = $column_label; } return $new_columns; } add_filter( 'manage_edit-shop_order_columns', 'woo_customer_order_coupon_column_for_orders' ); function woo_display_customer_order_coupon_in_column_for_orders( $column ) { global $the_order; if( $column == 'order_coupons' ) { if( $coupons = $the_order->get_used_coupons() ) { foreach( $coupons as $coupon_code ){ $coupon = new WC_Coupon($coupon_code); if( $coupon ){ echo "<span class='coupon-name'><b>".$coupon->code."</b></span>"; echo "<p class='coupon-description'>".$coupon->get_description()."</p>"; } } } else { echo '<small><em>'. __('No Coupon') . '</em></small>'; } } }

The new "Coupons" column, with the coupon name and description, should appear on the order list page in the admin panel. But for some reason, the coupons aren't showing.

I used get_coupon_codes instead of get_used_coupons. Nothing changed.

Order Page

Order List

I have a test site with a clean WordPress installation and only one WooCommerce plugin.

WordPress version - 6.9.1

WooCommerce version - 10.5.2

Twenty Twenty-Five theme

What could be the error in the code, and how can I fix it if there's an error?

Read Entire Article