Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
How you can Get WooCommerce Order Details?
1. How to Get WooCommerce Order Details?
As we know that, WooCommerce is the most popular platform for eCommerce
solutions, and it already has by default templates of each page with the default
template design.
So, sometimes we want to change the design of the template with our custom
template and in that template, we need order details to show as per custom
design.
Let’s get started.
Get WooCommerce Order Details
We have to send in the custom email body content. So there, we have to use the
WC_Order object to get WooCommerce order details.
We can also use the wc_get_orders(), this is function to get the order object and
get the order details on certain parameter.
RECENT POSTS
CATEGORIES
MOST VIEWED POSTS
FOLLOW US
Stay updated via social channels
HOW TO WOOCOMMERCE WORDPRESS
Blog Categories Tips & Tricks Contact
HOME WOOCOMMERCE HOW TO GET WOOCOMMERCE ORDER DETAILS?
AMAN MEHRA FEBRUARY 27, 2021 LEAVE A COMMENT
Tweet on Twitter Share on Facebook
How to Add WooCommerce Cart
Icon in Menu with Item Count?
How to Secure Password Using
bcrypt in PHP?
How to Make a DataTable in
ReactJS?
How to Inline Style in ReactJS?
How to Install WordPress Theme
(2021 Edition)?
How To
PHP
ReactJS
Tips & Tricks
WooCommerce
WordPress
WooCommerce Remove
Update Cart Button and
Make it Automatically
Update.
October 5, 2020
How to Change Price of
Speci c Product and
Quantity in Cart?
October 14, 2020
How to Redirect to
Checkout After Add to
Cart?
October 16, 2020
How can I Prevent SQL
Injection in PHP?
October 7, 2020
Upload Multiple Featured
Images in a Post OR Page
January 4, 2021
$order_id = 145;
$order = new WC_Order( $order_id );
//$order = wc_get_order( $order_id );
$orderid = $order->get_id(); // Get the order ID
$parent_id = $order->get_parent_id(); // Get the parent
$user_id = $order->get_user_id(); // Get the user ID
$user = $order->get_user(); // Get the WP_User obje
// Get Order Status
$order_status = $order->get_status(); // Get the order
// Get Order Dates
$date_created = $order->get_date_created(); // Get date
$date_modified = $order->get_date_modified(); // Get dat
$date_completed = $order->get_date_completed(); // Get o
$date_paid = $order->get_date_paid(); //Get order paid d
//Get Order Billing Details
$billing_first_name = $order->get_billing_first_name();
$billing_last_name = $order->get_billing_last_name();
$billing_company = $order->get_billing_company();
$billing_address1 = $order->get_billing_address_1();
$billing_address2 = $order->get_billing_address_2();
$billing_city = $order->get_billing_city();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2. So, we see how to get WooCoomerce order details with the help of getter
method. You can check more method here.
If you want to get and access the protected data of the order object then, you
can use the get_data() function.
It is the same as we did above with the instance of the $order object. E.g:
$order->get_data()
It will return the data as an associative array and we can use this array with
key=>pair value.
Let’s see the example.
$billing_state = $order->get_billing_state();
$billing_postcode = $order->get_billing_postcode();
$billing_country = $order->get_billing_country();
$billing_email = $order->get_billing_email();
$billing_phone = $order->get_billing_phone();
$billing_formatted_name = $order->get_formatted_billing_
$billing_formatted_address = $order->get_formatted_billi
//Get Order Shipping Details
$shipping_first_name = $order->get_shipping_first_name(
$shipping_last_name = $order->get_shipping_last_name();
$shipping_company = $order->get_shipping_company();
$shipping_address1 = $order->get_shipping_address_1();
$shipping_address2 = $order->get_shipping_address_2();
$shipping_city = $order->get_shipping_city();
$shipping_state = $order->get_shipping_state();
$shipping_postcode = $order->get_shipping_postcode();
$shipping_country = $order->get_shipping_country();
$shipping_formatted_name = $order->get_formatted_shippin
$shipping_formatted_address = $order->get_formatted_ship
//Get Order Payment Details
$currency = $order->get_currency(); // Get the curr
$payment_title = $order->get_payment_method_title(); //
$payment_method = $order->get_payment_method(); // Get t
$fees = $order->get_fees(); // Get the order fees
$subtotal = $order->get_subtotal(); // Get the order sub
$total_tax = $order->get_total_tax(); // Get the order t
$total = $order->get_total(); // Get the order total
$order_id = 145;
$order = wc_get_order( $order_id );
$order_data = $order->get_data(); // Get the Order data
$orderid = $order_data['id']; // Get the order ID
$parent_id = $order_data['parent_id']; // Get the parent
// Get Order Status
$order_status = $order_data['status']; // Get the order
// Get Order Dates
$date_created = $order_data['date_created']; // Get dat
$date_modified = $order_data['date_modified']; // Get da
$date_completed = $order_data['date_completed']; // Get
$date_paid = $order_data['date_paid']; //Get order paid
//Get Order Billing Details
$billing_first_name = $order_data['billing']['first_name
$billing_last_name = $order_data['billing']['last_name'
$billing_company = $order_data['billing']['company'];
$billing_address1 = $order_data['billing']['address_1']
$billing_address2 = $order_data['billing']['address_2']
$billing_city = $order_data['billing']['city'];
$billing_state = $order_data['billing']['state'];
$billing_postcode = $order_data['billing']['postcode'];
$billing_country = $order_data['billing']['country'];
$billing_email = $order_data['billing']['email'];
$billing_phone = $order_data['billing']['phone'];
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
3. How to Add WooCommerce Cart Icon
in Menu with Item Count?
How to Secure Password Using
bcrypt in PHP?
With the get_data() function you can use order data as a array properties for get
WooCommerce order details.
You can also loop the order items with get_items() function, if you have
multiple items in one order.
See the simple example to understand this.
Here, we loop the order items and get the value with getter method, as we used
in above.
So in this article we work with:
WC_Order
wc_get_order()
get_data()
get_items()
I hope you understand! how to get WooCommerce order details and use it?
YOU MAY ALSO LIKE
GET ORDER DETAILS
WOOCOMMERCE ORDER
WOOCOMMERCE ORDER DETAILS
Tweet on Twitter Share on Facebook
//Get Order Shipping Details
$shipping_first_name = $order_data['shipping']['first_na
$shipping_last_name = $order_data['shipping']['last_name
$shipping_company = $order_data['shipping']['company'];
$shipping_address1 = $order_data['shipping']['address_1
$shipping_address2 = $order_data['shipping']['address_2
$shipping_city = $order_data['shipping']['city'];
$shipping_state = $order_data['shipping']['state'];
$shipping_postcode = $order_data['shipping']['postcode'
$shipping_country = $order_data['shipping']['country'];
//Get Order Payment Details
$subtotal = $order_data['subtotal']; // Get the order su
$total_tax = $order_data['total_tax']; // Get the order
$total = $order_data['total']; // Get the order total
foreach ( $order->get_items() as $item_id => $item ) {
$product = $item->get_product();
$product_id = $item->get_product_id();
$variation_id = $item->get_variation_id();
$name = $item->get_name();
$quantity = $item->get_quantity();
$subtotal = $item->get_subtotal();
$total = $item->get_total();
$tax = $item->get_subtotal_tax();
$all_meta = $item->get_meta_data();
$single_meta = $item->get_meta( '_meta_key', true );
$type = $item->get_type();
//and so on...
}
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19