Coupons Used Column in the Orders List
Shows which coupon codes were used on each order in a new column on the admin orders screen.
Opens WPIDE on
Code
$wpide_coupon_column_add = function ( $columns ) {
$columns['wpide_coupons'] = 'Coupons';
return $columns;
};
$wpide_coupon_column_render = function ( $column, $order ) {
if ( 'wpide_coupons' !== $column ) {
return;
}
$order = $order instanceof WC_Order ? $order : wc_get_order( $order );
$codes = $order ? $order->get_coupon_codes() : array();
echo $codes ? esc_html( implode( ', ', $codes ) ) : '–';
};
add_filter( 'manage_woocommerce_page_wc-orders_columns', $wpide_coupon_column_add, 20 );
add_filter( 'manage_edit-shop_order_columns', $wpide_coupon_column_add, 20 );
add_action( 'manage_woocommerce_page_wc-orders_custom_column', $wpide_coupon_column_render, 10, 2 );
add_action( 'manage_shop_order_posts_custom_column', $wpide_coupon_column_render, 10, 2 );
Notes
Works with both the HPOS orders screen and the legacy posts-based screen.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.