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!
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.
Each order shows coupon codes in a styled badge format with the discount amount in parentheses, like: SUMMER20 ($15.00)
/**
* 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');
}
}
Something not working as expected? Need help customizing it for your specific needs?
Have an idea for functionality you're missing on your site? Tell us what you're looking for!
Share it with us! Our community loves learning and growing together.
No comments yet.