Add Coupon Column to WooCommerce Orders Admin Table

Beginner
✓ Tested
📅 August 24, 2025
⬇️ 0 Downloads
📋 0 Copies

This snippet adds a dedicated “Coupon” column to your WooCommerce orders admin table, making it easy to see which coupons were used for each order at a glance. No more clicking into individual orders to check coupon usage!

What does this code do?

Adds a new column in the WooCommerce orders list (WooCommerce → Orders) that displays the coupon code(s) used in each order along with the discount amount. Perfect for tracking coupon performance and identifying promotional campaign success.

Features:

  • Coupon Display: Shows coupon codes directly in the orders table
  • Discount Amount: Displays the actual discount value for each coupon
  • Multiple Coupons: Handles orders with multiple coupons elegantly
  • Visual Design: Styled badges make coupons easy to spot
  • Sortable Column: Sort orders by coupon usage
  • Clean Display: Shows “–” for orders without coupons

Perfect for:

  • Tracking marketing campaign effectiveness
  • Identifying popular discount codes
  • Quick coupon usage overview
  • Financial reporting and analysis
  • Customer service quick reference

What you’ll see:

Each order shows coupon codes in a styled badge format with the discount amount in parentheses, like: SUMMER20 ($15.00)

⚠️ Important Warnings

⚠️ Only works with WooCommerce 8.0+ (HPOS compatible)
⚠️ May need adjustments if using custom order table plugins
⚠️ Column width might need adjustment based on your screen resolution
⚠️ Sorting by coupon column uses basic alphabetical sorting
⚠️ Large coupon codes might wrap on smaller screens
⚠️ Discount amounts shown are per-coupon, not percentage
⚠️ Some themes might override the admin styles
💻 PHP Code
/**
 * Add coupon column to WooCommerce orders admin table
 * Shows used coupons and discount amounts for each order
 * Prefix: tpsc_ (TP Snippet Collection)
 */

// Add coupon column to orders table
add_filter('manage_woocommerce_page_wc-orders_columns', 'tpsc_add_coupon_column_to_orders');
function tpsc_add_coupon_column_to_orders($columns) {
    $new_columns = array();
   
    foreach ($columns as $column_name => $column_info) {
        $new_columns[$column_name] = $column_info;
       
        // Add after order total column
        if ('order_total' === $column_name) {
            $new_columns['order_coupon'] = __('Coupon', 'woocommerce');
        }
    }
   
    return $new_columns;
}

// Add content to coupon column
add_action('manage_woocommerce_page_wc-orders_custom_column', 'tpsc_add_coupon_column_content', 10, 2);
function tpsc_add_coupon_column_content($column, $order) {
    if ('order_coupon' === $column) {
        if (!is_a($order, 'WC_Order')) {
            $order = wc_get_order($order);
        }
       
        if (!$order) {
            return;
        }
       
        $coupons = $order->get_coupon_codes();
       
        if (!empty($coupons)) {
            $coupon_list = array();
           
            foreach ($coupons as $coupon_code) {
                $coupon = new WC_Coupon($coupon_code);
                $discount_amount = $order->get_discount_total();
                
                // Get individual coupon discount if multiple coupons
                $coupon_discount = 0;
                foreach ($order->get_items('coupon') as $coupon_item) {
                    if ($coupon_item->get_code() === $coupon_code) {
                        $coupon_discount = $coupon_item->get_discount();
                        break;
                    }
                }
               
                if ($coupon_discount > 0) {
                    $coupon_list[] = sprintf(
                        '<span class="tpsc-order-coupon">%s <small>(%s)</small></span>',
                        esc_html($coupon_code),
                        wc_price($coupon_discount)
                    );
                } else {
                    $coupon_list[] = sprintf(
                        '<span class="tpsc-order-coupon">%s</span>',
                        esc_html($coupon_code)
                    );
                }
            }
           
            echo implode('<br>', $coupon_list);
        } else {
            echo '<span class="na">–</span>';
        }
    }
}

// Add styles for coupon column
add_action('admin_head', 'tpsc_add_coupon_column_styles');
function tpsc_add_coupon_column_styles() {
    $screen = get_current_screen();
   
    if ($screen && 'woocommerce_page_wc-orders' === $screen->id) {
        ?>
        <style>
            .tpsc-order-coupon {
                display: inline-block;
                padding: 3px 8px;
                background: linear-gradient(135deg, #f7f0cd 0%, #f0e9b8 100%);
                border: 1px solid #e5d99c;
                border-radius: 4px;
                font-size: 12px;
                font-weight: 600;
                color: #7a6a00;
                line-height: 1.4;
                white-space: nowrap;
            }
            .tpsc-order-coupon small {
                color: #666;
                font-weight: normal;
                margin-left: 4px;
            }
            .column-order_coupon {
                width: 10%;
                min-width: 100px;
            }
            .widefat .column-order_coupon {
                text-align: left;
            }
            /* Hover effect */
            .tpsc-order-coupon:hover {
                background: linear-gradient(135deg, #f5edc4 0%, #ede5ad 100%);
                transform: translateY(-1px);
                box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            }
            /* Multiple coupons spacing */
            .column-order_coupon br {
                content: "";
                display: block;
                margin: 3px 0;
            }
        </style>
        <?php
    }
}

// Make column sortable (optional)
add_filter('manage_woocommerce_page_wc-orders_sortable_columns', 'tpsc_make_coupon_column_sortable');
function tpsc_make_coupon_column_sortable($columns) {
    $columns['order_coupon'] = 'has_coupon';
    return $columns;
}

// Handle sorting logic
add_action('pre_get_posts', 'tpsc_handle_coupon_column_sorting');
function tpsc_handle_coupon_column_sorting($query) {
    if (!is_admin() || !$query->is_main_query()) {
        return;
    }
    
    if ('has_coupon' === $query->get('orderby')) {
        $query->set('meta_key', '_coupon_codes');
        $query->set('orderby', 'meta_value');
    }
}

📝 Installation Instructions

INSTALLATION:
1. Copy the entire code
2. Go to WordPress Admin → Appearance → Theme Editor → functions.php
3. Paste at the bottom of the file
4. Save changes
5. Go to WooCommerce → Orders to see the new column

WHERE IT APPEARS:
- WooCommerce → Orders (main orders table)
- Works with both HPOS and legacy orders
- Column appears after the "Total" column

CUSTOMIZATION:
To change column position:
- Find line: if ('order_total' === $column_name)
- Replace 'order_total' with another column name like 'order_status' or 'order_date'

To change column width:
- Find: width: 10%;
- Adjust percentage as needed

To change badge colors:
- Modify the background gradient colors in the CSS section
- Current: Gold/yellow theme
- Can be changed to match your brand

TESTING:
1. Create a test order with a coupon
2. Check WooCommerce → Orders
3. Verify coupon appears in new column
4. Try sorting by the coupon column

📸 Screenshots