So short version is that I am trying to add an extra column in the orders page and have it populated with the custom field I have created for the users on the site (The name for the custom field is account_manager)
What I'm trying to achieve is for it display the customers account manager in a column in the orders section. Bit of a strange request I know!
I had a look at a few guides and tutorials regarding columns and meta data but it all seemed to be regarding the orders rather than data from the customer directly.
Any help would be greatly appreciated. I don't mind having a go, I just need a little guidance :)
I've tried this but it's not returning any values
function wc_orders_add_account_manager_column($columns)
{
$new_columns = [];
foreach ( $columns as $column_name => $column_info ) {
$new_columns[ $column_name ] = $column_info;
if ( 'order_status' === $column_name ) { // Change order_status to manage column orders
$new_columns['account_manager'] = 'Account Manager';
}
}
return $new_columns;
}
add_filter( 'manage_edit-shop_order_columns', 'wc_orders_add_account_manager_column', 20 );
/**
* Adds 'account_manager' column content to 'Orders' page
*
* @param string $column name of column being displayed
*/
function wc_orders_add_account_manager_column_content($column)
{
global $post;
$order_id = $post->ID;
// Get an instance of the WC_Order object
$order = wc_get_order($order_id);
// Get the user ID from WC_Order methods
$user_id = $order->get_customer_id(); // or $order->get_customer_id();
$meta = get_user_meta($user_id, 'account_manager', true);
return $meta;
if ( 'account_manager' === $columns ) {
echo $meta ;
} else {
echo "Not Valid!";
}
}
add_action( 'manage_shop_order_posts_custom_column', 'wc_orders_add_account_manager_column_content' );