get customer details from order id in woocommerce code example
Example 1: get order details by id woocommerce
$order = wc_get_order( $order_id );
$order_data = $order->get_data();
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_currency = $order_data['currency'];
$order_version = $order_data['version'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method_title = $order_data['payment_method_title'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method = $order_data['payment_method'];
$order_date_created = $order_data['date_created']->date('Y-m-d H:i:s');
$order_date_modified = $order_data['date_modified']->date('Y-m-d H:i:s');
$order_timestamp_created = $order_data['date_created']->getTimestamp();
$order_timestamp_modified = $order_data['date_modified']->getTimestamp();
$order_discount_total = $order_data['discount_total'];
$order_discount_tax = $order_data['discount_tax'];
$order_shipping_total = $order_data['shipping_total'];
$order_shipping_tax = $order_data['shipping_tax'];
$order_total = $order_data['cart_tax'];
$order_total_tax = $order_data['total_tax'];
$order_customer_id = $order_data['customer_id'];
$order_billing_first_name = $order_data['billing']['first_name'];
$order_billing_last_name = $order_data['billing']['last_name'];
$order_billing_company = $order_data['billing']['company'];
$order_billing_address_1 = $order_data['billing']['address_1'];
$order_billing_address_2 = $order_data['billing']['address_2'];
$order_billing_city = $order_data['billing']['city'];
$order_billing_state = $order_data['billing']['state'];
$order_billing_postcode = $order_data['billing']['postcode'];
$order_billing_country = $order_data['billing']['country'];
$order_billing_email = $order_data['billing']['email'];
$order_billing_phone = $order_data['billing']['phone'];
$order_shipping_first_name = $order_data['shipping']['first_name'];
$order_shipping_last_name = $order_data['shipping']['last_name'];
$order_shipping_company = $order_data['shipping']['company'];
$order_shipping_address_1 = $order_data['shipping']['address_1'];
$order_shipping_address_2 = $order_data['shipping']['address_2'];
$order_shipping_city = $order_data['shipping']['city'];
$order_shipping_state = $order_data['shipping']['state'];
$order_shipping_postcode = $order_data['shipping']['postcode'];
$order_shipping_country = $order_data['shipping']['country'];
Example 2: get order details by id woocommerce
$order = wc_get_order( $order_id );
$order_id = $order->get_id();
$parent_id = $order->get_parent_id();
$user_id = $order->get_user_id();
$user = $order->get_user();
$order_status = $order->get_status();
$currency = $order->get_currency();
$payment_method = $order->get_payment_method();
$payment_title = $order->get_payment_method_title();
$date_created = $order->get_date_created();
$date_modified = $order->get_date_modified();
$billing_country = $order->get_billing_country();
Example 3: get billing address in woocommerce
$user_id = get_post_meta( $order_id, '_customer_user', true );
$customer = new WC_Customer( $user_id );
$username = $customer->get_username();
$user_email = $customer->get_email();
$first_name = $customer->get_first_name();
$last_name = $customer->get_last_name();
$display_name = $customer->get_display_name();
$billing_first_name = $customer->get_billing_first_name();
$billing_last_name = $customer->get_billing_last_name();
$billing_company = $customer->get_billing_company();
$billing_address_1 = $customer->get_billing_address_1();
$billing_address_2 = $customer->get_billing_address_2();
$billing_city = $customer->get_billing_city();
$billing_state = $customer->get_billing_state();
$billing_postcode = $customer->get_billing_postcode();
$billing_country = $customer->get_billing_country();
$shipping_first_name = $customer->get_shipping_first_name();
$shipping_last_name = $customer->get_shipping_last_name();
$shipping_company = $customer->get_shipping_company();
$shipping_address_1 = $customer->get_shipping_address_1();
$shipping_address_2 = $customer->get_shipping_address_2();
$shipping_city = $customer->get_shipping_city();
$shipping_state = $customer->get_shipping_state();
$shipping_postcode = $customer->get_shipping_postcode();
$shipping_country = $customer->get_shipping_country();