-1

i want to display used coupons on WooCommerce admin orders list with the coupon description. So i'm using Display used coupons on WooCommerce admin orders list answer code and the used coupon code is shown, but can't include the used coupon description.

How is that possible?

7uc1f3r
  • 28,449
  • 17
  • 32
  • 50

1 Answers1

0

You can coupon object by WC_Coupon class and use $coupon->get_description() to get coupon description. try the below code.

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>';
        }
    }
}
add_action( 'manage_shop_order_posts_custom_column' , 'woo_display_customer_order_coupon_in_column_for_orders' );

Tested and works

enter image description hereenter image description here

Bhautik
  • 11,125
  • 3
  • 16
  • 38