Reputation: 123
My client wants to have all woocommerce clients to have a unique customer id which is assigned by the admin on register. I managed to create the custom field for that and to store the number in database. Now they want to have that assigned customer number to show on order details page under General in admin Edit order. How can I retrieve and show that data for current order using get_the_author_meta.
I have tried using get_the_author_meta since the data is stored under usermeta table in db.
// Code in my functions.php
<?php
function webweb_display_order_data_in_admin( $order ){
if ( 'customer_number' != $column ) return;
global $the_order;
// Get the customer id
$user_id = $the_order->get_customer_id();
if( ! empty($user_id) && $user_id != 0) {
$user_data = get_the_author_meta( 'customer_number', $user_id );
echo $user_data;
}
else
echo '-';
}
add_action( 'woocommerce_admin_order_data_after_order_details', 'webweb_display_order_data_in_admin' );
Upvotes: 0
Views: 252
Reputation: 123
This is what I had to add using get_user_meta suggested by LoicTheAztec
function webweb_display_order_data_in_admin( $order ){ ?>
<div class="order_data_column">
<?php
$user_id = $order->get_user_id();
$key = 'membership_number';
$single = true;
$user_membership_number = get_user_meta( $user_id, $key, $single );
echo '<p><strong>' . __( 'Membership Number' ) . ': </strong>' . $user_membership_number . '</p>';
?>
</div>
<?php }
add_action( 'woocommerce_admin_order_data_after_order_details',
'webweb_display_order_data_in_admin' );
Upvotes: 1