How to Get Order Details by Order ID

How to Get Order Details by Order ID

Order graphics

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

Share this Post:

About 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.  

Related Posts:

17 thoughts on “How to Get Order Details by Order ID

  1. williamstuart3y24w@yahoo.com'

    is this work with WooCommerce 3.2.4?

    Reply
  2. rubyfaitho1z82d0@yahoo.com'

    worked liked a charm!

    Reply
  3. amit.kate21@gmail.com'

    $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.

    Reply
  4. pedromcosta@gmail.com'

    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

    Reply
  5. victormacclien@gmail.com'

    Nice post! I solve my issue

    Reply
  6. alexanderouteiral@gmail.com'

    Where can i put this code?

    I tried put in public_html/check.php and i dont understand.

    Sorry for inconvenience

    Reply
  7. steven1066@hotmail.com'

    May I simply say what a comfort to find someone that genuinely understands what they’re discussing on the internet.
    You certainly understand how to bring an issue to light and make it important.
    A lot more people must look at this and understand this side of your story.
    I was surprised you are not more popular given that you certainly possess the gift.

    Reply
  8. kashyap8811@gmail.com'

    Hi, I’m getting this:

    PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function WC_PB_REST_API::legacy_order_response(), 3 passed

    Reply
  9. amandainjames@gmail.com'

    I want to display customer information on order page for which I am adding this code in functions.php but it is not showing me the actual output

    add_action( 'woocommerce_admin_order_data_after_billing_address', 'order_customer_information');
    function order_customer_information( $order ){
    global $post;

    $customer_user = get_post_meta( $post->ID, '_customer_user', true );
    echo ''.__('Order Customer name').': ' . get_user_meta( $customer_user, 'customername', true ) . '';
    }

    Here is the refernce that I am using to implement the whole process Display Customer Order Details

    Reply
    • Hi Amanda,

      I have couple of question over here.
      #1: Are you saving customername, because by default no such key is present in usermeta table
      #2: Why are you using $post where you have $order

      I have modified your code a little bit and it worked for me, here is the sample:
      add_action('woocommerce_admin_order_data_after_billing_address', 'order_customer_information');
      function order_customer_information($order) {
      if(!empty($order->get_user_id()))
      {
      echo __('Order Customer Name: ') . get_user_meta($order->get_user_id(), 'nickname', true); //replace the key with your custom key
      }
      }

      Reply

Leave a Reply to Richard Rhini Cancel reply

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


*