Get Order Details From Order Object

get order details from order object

Get Order Details From Order Object

 |   |  0
WooCommerce WordPress

How to get order details from order object? in WooCommerce Here, I like to save your time by this article.

Order details:

// Get an instance of the WC_Order object (same as before)
$order = wc_get_order( $order_id );
 
// Get the order ID
$order_id = $order->get_id();
 
$order_id = $order->get_user_id();
$public_view_order_url = esc_url( $order->get_view_order_url() );
$items = $order->get_items();
$total = $order->get_total();
$order_number = $order->get_order_number();
$created_at = $order->get_date_created()->date('Y-m-d H:i:s');
$updated_at = $order->get_date_modified()->date('Y-m-d H:i:s');
$completed_at = !empty($order->get_date_completed()) ? $order->get_date_completed()->date('Y-m-d H:i:s') : '';
$status = $order->get_status();
$currency = $order->get_currency();
$total = wc_format_decimal($order->get_total(), $dp);
$subtotal = wc_format_decimal($order->get_subtotal(), $dp);
$total_line_items_quantity = $order->get_item_count();
$total_tax = wc_format_decimal($order->get_total_tax(), $dp);
$total_shipping = wc_format_decimal($order->get_total_shipping(), $dp);
$cart_tax = wc_format_decimal($order->get_cart_tax(), $dp);
$shipping_tax = wc_format_decimal($order->get_shipping_tax(), $dp);
$total_discount = wc_format_decimal($order->get_total_discount(), $dp);
$shipping_methods = $order->get_shipping_method();
$order_key = $order->get_order_key();
 
// payment details
$method_id = $order->get_payment_method();
$method_title = $order->get_payment_method_title();
$paid_at = !empty($order->get_date_paid()) ? $order->get_date_paid()->date('Y-m-d H:i:s') : '';
 
// billing_address
$first_name = $order->get_billing_first_name();
$last_name = $order->get_billing_last_name();
$company = $order->get_billing_company();
$address_1 = $order->get_billing_address_1();
$address_2 = $order->get_billing_address_2();
$city = $order->get_billing_city();
$state = $order->get_billing_state();
$formated_state = WC()->countries->states[$order->get_billing_country()][$order->get_billing_state()]; //human readable formated state name
$postcode = $order->get_billing_postcode();
$country = $order->get_billing_country();
$formated_country = WC()->countries->countries[$order->get_billing_country()]; //human readable formated country name
$email = $order->get_billing_email();
$phone = $order->get_billing_phone();
 
// Shipping_address
$first_name = $order->get_shipping_first_name();
$last_name = $order->get_shipping_last_name();
$company = $order->get_shipping_company();
$address_1 = $order->get_shipping_address_1();
$address_2 = $order->get_shipping_address_2();
$city = $order->get_shipping_city();
$state = $order->get_shipping_state();
$formated_state = WC()->countries->states[$order->get_shipping_country()][$order->get_shipping_state()]; //human readable formated state name
$postcode = $order->get_shipping_postcode();
$country = $order->get_shipping_country();
$formated_country = WC()->countries->countries[$order->get_shipping_country()]; //human readable formated country name
 
// Extra
$note = $order->get_customer_note();
$customer_ip = $order->get_customer_ip_address();
$customer_user_agent = $order->get_customer_user_agent();
$customer_id = $order->get_user_id();
$view_order_url = $order->get_view_order_url();

Enjoy…


0 Claps

Show your love in the form of Claps and Comments...

Comments...

No comments found. Leave your reply here.