Display WooCommerce Order Customer Username on Edit Order Page

When viewing or editing a WooCommerce order, it can be pretty handy to add custom data to the page to avoid having to switch between pages. Today, i’ll provide a quick snippet that will add to the edit/view order page the customer username and a link to its user profile.

<?php
// Add WooCommerce customer username to edit/view order admin page
add_action( 'woocommerce_admin_order_data_after_billing_address', 'woo_display_order_username', 10, 1 );

function woo_display_order_username( $order ){

    global $post;

	$customer_user = get_post_meta( $post->ID, '_customer_user', true );
    echo '<p><strong style="display: block;">'.__('Customer Username').':</strong> <a href="user-edit.php?user_id=' . $customer_user . '">' . get_user_meta( $customer_user, 'nickname', true ) . '</a></p>';
}

The result in action:

add-customer-username-to-order

Pretty handy right?

So, to add this feature to your site, simply place the following snippet in the functions.php file within your theme folder and you’re done!