I have a function that does this:
$order = new WC_Order($order_id);
$customer = new WC_Customer($order_id);
How can I get customer details fr
I just dealt with this. Depending on what you really want, you can get the details from the order like this:
$field = get_post_meta($order->id, $field_name, true);
Where $field_name is '_billing_address_1' or '_shipping_address_1'or 'first_name'. You can google the other fields, but don't forget the "" at the beginning.
If you want to retrieve the customer for this order, and get its field directly, it works as in your solution, except you do not need to retrieve the full customer object:
$customer_id = (int)$order->user_id;
$field = get_user_meta($customer_id, $field_name, true);
Now in this case, the $field_name does not start with "_". For example: 'first_name' and 'billing_address_1'.