Website Building » WooCommerce » How Can I Get the Order ID in WooCommerce?

How Can I Get the Order ID in WooCommerce?

Last updated on January 22, 2023 @ 2:49 pm

If you’re running a WooCommerce store, you’ve probably come across the need to get the order ID for one reason or another. Maybe you’re trying to troubleshoot an issue for a customer, or perhaps you’re developing a custom plugin and need to access order data.

Either way, in this article we’ll show you four different ways that you can get the order ID in WooCommerce.

Method 1: Get the Order ID from the Order Page

The first and easiest way to get the order ID is from the order page itself. If you go to WooCommerce > Orders in your WordPress dashboard, you’ll see a list of all recent orders. Each order has an order number next to it.

You can click on any order number to view more details about that order. Once you’re on the single order page, look in the top right corner for the Order Details box.

The very first item in this box is the Order number (or ID). You can also see other important pieces of information like the date placed, customer name, and payment status.

PRO TIP: If you are thinking about how to get the order ID in WooCommerce, please be aware that this is not possible. The order ID is generated by WooCommerce and is not something that you can control.

Method 2: Get the Order ID from the Edit Order Page

If you need to programmatically get an order’s information (like its items, billing address, etc.), then you need its numeric ID.

To get that, go to WooCommerce > Orders and hover over any order number. This will reveal a set of links, one of which is Edit.

Click on Edit and you’ll be taken to the Edit Order page for that particular order. In the top right corner of this page is another Order Details box.

This time, however, you’ll see the Order ID in numeric form. This is the ID that you can use in code to programmatically access order data.

Method 3: Get the Order ID using the WooCommerce Order Object

Another way to get the order ID is by using the WooCommerce order object. This is a useful method if you’re working on a custom plugin or theme and need to access order data within your code.

To get the order ID using this method, you’ll first need to get the order object. You can do this by using the wc_get_order() function and passing in the order ID or order object.

For example, if you have the order ID and want to get the order object:

$order = wc_get_order( $order_id );

Once you have the order object, you can access the order ID using the following code:

$order_id = $order->get_id();

Method 4: Get the Order ID using the Order’s Shortcode

The last way to get the order ID is by using the order’s shortcode. This is a useful method if you’re working on a custom plugin or theme and need to display order data on the front-end of your website.

To get the order ID using this method, you’ll need to use the [order_id] shortcode. This shortcode will display the order ID on the front-end of your website.

For example, if you want to display the order ID on the “Thank you” page after a customer has placed an order, you can use the following code:

<p>Your Order ID is: [order_id]</p>

With these four methods, you should now have a good understanding of how to get the order ID in WooCommerce. Whether you’re troubleshooting an issue for a customer or developing a custom plugin, these methods will come in handy when you need to access order data.

Morgan Bash

Morgan Bash

Technology enthusiast and Co-Founder of Women Coders SF.