How To Display Customer Order Details in WooCommerce
When processing a WooCommerce order, you often need information that is not available on the order page, thus, you need to switch pages or go to the customer database to get the information. Often, the most common information item is the customer username and profile.
By default WooCommerce order page shows limited information about the Orders in the admin panel.
In this tutorial, I will demonstrate how to display customer information on the order page. The good news is that all you have to do is to place a simple snippet at the end of the functions.php file of the theme.
1 2 3 4 5 6 7 |
add_action( 'woocommerce_admin_order_data_after_billing_address', 'wpblog_order_customer_information'); function wpblog_order_customer_information( $order ){ global $post; $customer_user = get_post_meta( $post->ID, '_customer_user', true ); echo '<p><strong style="display: block;">'.__('Order Customer name').':</strong> <a href="user-edit.php?user_id=' . $customer_user . '">' . get_user_meta( $customer_user, 'customername', true ) . '</a></p>'; } |
woocommerce_admin_order_data_after_billing_address is WooCommerce hook used to display admin data.
wpblog_order_customer_information is a function used to display user information through get_user_meta.
Get Customer Details From Orders – The Alternate Method
Here is another function that adds similar functionality and get customer information at the order page:
1 2 3 4 5 6 7 8 |
add_action( 'woocommerce_admin_order_data_after_billing_address', 'wpblog_anothermethod_display'); function wpblog_anothermethod_display( $order ){ $order_id =43; $order_meta = get_post_meta($order_id); print("<pre>"); print_r($order_meta); print("</pre>"); } |
$order_meta uses get_post_meta, which is meta key to return data on the basis of order_id.
Note: add the above code in functions.php which located in your theme folder or whenever you want to display the information about order details
Conclusion
In this short tutorial, I showed how you could easily add information to WooCommerce order page. If you need help, just drop a comment below.
Bonus Content
How to Add/Set Custom Order Status in WooCommerce Stores
Create Faster WordPress Websites!
Free eBook on WordPress Performance right in your inbox.