How to Get Order Details by Order ID

Wondering how to get the WooCommerce full order details by Order ID? Don't worry in this tutorial I have written one function that will help to get the details in a fraction of a second.

In early 2008 when I started working in WordPress/WooCommerce I hardly know StackOverflow and WooCommerce API, so I had to write several API for some of our web service. Then I had written this function to get order details by order/post ID. Hope this function will be helpful for you as well.

WooCommerce 3.x or above

WooCommerce 2.6.x or below

Okay now, how do I use it?

First add getOrderDetailById() to your active theme functions.php or to any active plugin PHP file.
Then call getOrderDetailById() from anywhere in your app by passing the Order ID like below.

Using WooCommerce Shipment Tracking and want’s to add that as well?

WooCommerce Shipment Tracking is an awesome paid plugin that you must have! If you want to add this in your custom order detail function then just add below code in above mentions.

For Shipment Tracking 1.4.0 or above

For Shipment Tracking 1.3.6 or below

Default image
Raunak Gupta
I'm an expert Laravel, WooCommerce, WordPress theme and plugin developer, over the time I have developed several sites and applications. I like to help the upcoming developer, So I share my experience through this blog.
Articles: 18


  1. is this work with WooCommerce 3.2.4?

  2. worked liked a charm!

  3. $order = wc_get_order(20);

    while using above code,i m getting error as

    Fatal error: Call to a member function get_id() on boolean in.

    Please let me know, where i did mistake.

    Thanks in advance.

  4. Hi, I’m getting this:

    Warning: Missing argument 4 for WC_PB_REST_API::legacy_order_response() in (…)/wp-content/plugins/woocommerce-product-bundles/includes/class-wc-pb-rest-api.php on line 1074

  5. Nice post! I solve my issue

  6. Pedro Joaquin Martinez de Pinillos Vega
    Pedro Joaquin Martinez de Pinillos Vega

    It throws

    CRITICAL Uncaught Error: Call to undefined function getOrderById()

Leave a Reply