I need to add a custom column "Customer" in the backend of WooCommerce orders list.
Here is some code that add additional columns to admin orders list and displays the user ID:
add_filter( 'manage_edit-shop_order_columns', 'add_new_order_admin_list_column' );
function add_new_order_admin_list_column( $columns ) {
$columns['user_id'] = 'Kunde';
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'add_new_order_admin_list_column_content' );
function add_new_order_admin_list_column_content( $column ) {
global $post;
if ( 'user_id' === $column ) {
$order = wc_get_order( $post->ID );
echo $order->get_user_id();
}
}
How to display the "User login" instead of the user ID?
To display the "user login" in a custom column on admin orders list, you can use the following:
Code goes in functions.php file of your child theme (or in a plugin). Tested and works.