0% found this document useful (0 votes)
52 views4 pages

How You Can Get Woocommerce Order Details

If you are a beginner and doing customization in woocommerce and want to get order details of specific orders the check this file.

Uploaded by

Aman Mehra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views4 pages

How You Can Get Woocommerce Order Details

If you are a beginner and doing customization in woocommerce and want to get order details of specific orders the check this file.

Uploaded by

Aman Mehra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Blog Categories  Tips & Tricks Contact

HOME WOOCOMMERCE HOW TO GET WOOCOMMERCE ORDER DETAILS?


RECENT POSTS

How to Add WooCommerce Cart


Icon in Menu with Item Count?
How to Get WooCommerce Order Details?
How to Secure Password Using
HOW TO WOOCOMMERCE WORDPRESS bcrypt in PHP?

AMAN MEHRA FEBRUARY 27, 2021 LEAVE A COMMENT How to Make a DataTable in
ReactJS?
Tweet on Twitter Share on Facebook
How to Inline Style in ReactJS?

How to Install WordPress Theme


(2021 Edition)?

CATEGORIES

How To

PHP

ReactJS

Tips & Tricks

WooCommerce

As we know that, WooCommerce is the most popular platform for eCommerce WordPress

solutions, and it already has by default templates of each page with the default
template design.
MOST VIEWED POSTS
So, sometimes we want to change the design of the template with our custom WooCommerce Remove
template and in that template, we need order details to show as per custom Update Cart Button and
Make it Automatically
design.
Update.
October 5, 2020
Let’s get started.
How to Change Price of
Speci c Product and
Get WooCommerce Order Details Quantity in Cart?
October 14, 2020

We have to send in the custom email body content. So there, we have to use the How to Redirect to
Checkout After Add to
WC_Order object to get WooCommerce order details.
Cart?
We can also use the wc_get_orders(), this is function to get the order object and October 16, 2020
get the order details on certain parameter.
How can I Prevent SQL
Injection in PHP?
1 $order_id = 145; October 7, 2020
2 $order = new WC_Order( $order_id );
3 //$order = wc_get_order( $order_id );
Upload Multiple Featured
4
Images in a Post OR Page
5 $orderid = $order->get_id(); // Get the order ID January 4, 2021
6 $parent_id = $order->get_parent_id(); // Get the parent
7
8 $user_id = $order->get_user_id(); // Get the user ID
9 $user = $order->get_user(); // Get the WP_User obje
FOLLOW US
10
Stay updated via social channels
11 // Get Order Status
12 $order_status = $order->get_status(); // Get the order
13
14 // Get Order Dates
15 $date_created = $order->get_date_created(); // Get date
16 $date_modified = $order->get_date_modified(); // Get dat
17 $date_completed = $order->get_date_completed(); // Get o
18 $date_paid = $order->get_date_paid(); //Get order paid d
19
20 //Get Order Billing Details
21 $billing_first_name = $order->get_billing_first_name();
22 $billing_last_name = $order->get_billing_last_name();
23 $billing_company = $order->get_billing_company();
24 $billing_address1 = $order->get_billing_address_1();
25 $billing_address2 = $order->get_billing_address_2();
26 $billing_city = $order->get_billing_city();
27 $billing_state = $order->get_billing_state();
28 $billing_postcode = $order->get_billing_postcode();
29 $billing_country = $order->get_billing_country();
30 $billing_email = $order->get_billing_email();
31 $billing_phone = $order->get_billing_phone();
32 $billing_formatted_name = $order->get_formatted_billing_
33 $billing_formatted_address = $order->get_formatted_billi
34
35 //Get Order Shipping Details
36 $shipping_first_name = $order->get_shipping_first_name(
37 $shipping_last_name = $order->get_shipping_last_name();
38 $shipping_company = $order->get_shipping_company();
39 $shipping_address1 = $order->get_shipping_address_1();
40 $shipping_address2 = $order->get_shipping_address_2();
41 $shipping_city = $order->get_shipping_city();
42 $shipping_state = $order->get_shipping_state();
43 $shipping_postcode = $order->get_shipping_postcode();
44 $shipping_country = $order->get_shipping_country();
45 $shipping_formatted_name = $order->get_formatted_shippin
46 $shipping_formatted_address = $order->get_formatted_ship
47
48 //Get Order Payment Details
49 $currency = $order->get_currency(); // Get the curr
50 $payment_title = $order->get_payment_method_title(); //
51 $payment_method = $order->get_payment_method(); // Get t
52 $fees = $order->get_fees(); // Get the order fees
53 $subtotal = $order->get_subtotal(); // Get the order sub
54 $total_tax = $order->get_total_tax(); // Get the order t
55 $total = $order->get_total(); // Get the order total

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.

1 $order_id = 145;
2 $order = wc_get_order( $order_id );
3
4 $order_data = $order->get_data(); // Get the Order data
5 $orderid = $order_data['id']; // Get the order ID
6 $parent_id = $order_data['parent_id']; // Get the parent
7
8 // Get Order Status
9 $order_status = $order_data['status']; // Get the order
10
11 // Get Order Dates
12 $date_created = $order_data['date_created']; // Get dat
13 $date_modified = $order_data['date_modified']; // Get da
14 $date_completed = $order_data['date_completed']; // Get
15 $date_paid = $order_data['date_paid']; //Get order paid
16
17 //Get Order Billing Details
18 $billing_first_name = $order_data['billing']['first_name
19 $billing_last_name = $order_data['billing']['last_name'
20 $billing_company = $order_data['billing']['company'];
21 $billing_address1 = $order_data['billing']['address_1']
22 $billing_address2 = $order_data['billing']['address_2']
23 $billing_city = $order_data['billing']['city'];
24 $billing_state = $order_data['billing']['state'];
25 $billing_postcode = $order_data['billing']['postcode'];
26 $billing_country = $order_data['billing']['country'];
27 $billing_email = $order_data['billing']['email'];
28 $billing_phone = $order_data['billing']['phone'];
29
30 //Get Order Shipping Details
31 $shipping_first_name = $order_data['shipping']['first_na
32 $shipping_last_name = $order_data['shipping']['last_name
33 $shipping_company = $order_data['shipping']['company'];
34 $shipping_address1 = $order_data['shipping']['address_1
35 $shipping_address2 = $order_data['shipping']['address_2
36 $shipping_city = $order_data['shipping']['city'];
37 $shipping_state = $order_data['shipping']['state'];
38 $shipping_postcode = $order_data['shipping']['postcode'
39 $shipping_country = $order_data['shipping']['country'];
40
41 //Get Order Payment Details
42 $subtotal = $order_data['subtotal']; // Get the order su
43 $total_tax = $order_data['total_tax']; // Get the order
44 $total = $order_data['total']; // Get the order total

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.

1 foreach ( $order->get_items() as $item_id => $item ) {


2 $product = $item->get_product();
3 $product_id = $item->get_product_id();
4 $variation_id = $item->get_variation_id();
5
6 $name = $item->get_name();
7 $quantity = $item->get_quantity();
8
9 $subtotal = $item->get_subtotal();
10 $total = $item->get_total();
11 $tax = $item->get_subtotal_tax();
12
13 $all_meta = $item->get_meta_data();
14 $single_meta = $item->get_meta( '_meta_key', true );
15
16 $type = $item->get_type();
17
18 //and so on...
19 }

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?

GET ORDER DETAILS WOOCOMMERCE ORDER WOOCOMMERCE ORDER DETAILS

Tweet on Twitter Share on Facebook

YOU MAY ALSO LIKE

How to Add WooCommerce Cart Icon How to Secure Password Using


in Menu with Item Count? bcrypt in PHP?
How to Make a DataTable in How to Inline Style in ReactJS?
ReactJS?

How to Install WordPress Theme How to Install WordPress –


(2021 Edition)? Beginners Guide?

ABOUT THE AUTHOR: AMAN MEHRA


Hey! I'm Aman Mehra and I'm a full-stack developer and have 5+
years of experience. I love coding and nd solutions to bugs.

LEAVE A REPLY

Your email address will not be published. Required elds are marked *

Comment

Name * Email * Website

Save my name, email, and website in this browser for the next time I comment.

POST COMMENT

ABOUT QUICK LINKS RECENT POSTS JOIN OUR NEWSLETTER

Your Blog Coach is the best site Blog How to Add WooCommerce Cart Name
for nding the solution to any Icon in Menu with Item Count?
WordPress
issue related to coding and learn
How to Secure Password Using
more cool stuff and tricks. WooCommerce Email
bcrypt in PHP?
Contact
How to Make a DataTable in
ReactJS?
SUBSCRIBE

© 2020 Your Blog Coach Privacy Policy Terms and Conditions Sitemap

You might also like