Using WooCommerce REST API to query assigned order locations

When a WooCommerce order is placed and automatically/manually routed to a warehouse location using our integration, that assignment can be used with external integrations if needed when querying an order - due to our seamless integration with the WooCommerce REST API.

Once a location has been added in our integration, it will be assigned an ID. This is the ID that is used in the background when we assign/route an order to a specific location.

A location is assigned to an order on a per-line item basis - and this can be managed within the order in the WooCommerce Admin within each line item, like the example above.

Querying orders over REST API

wp-json/wc/v3/orders

When using the default WooCommerce REST API to query orders, we include a warehouse ID designation in two places in the existing/default WooCommerce API response for each order:

Full WooCommerce API Response Example:https://myworks.d.pr/oj2iqR

  1. Inside a top-level variable called warehouse:
     "warehouse": "204",

Inside each line_item value, inside the meta_data variable, as the key _order_item_wh. (Helpful for line items split to different locations in a single order)

"line_items": [
{
"id": 31,
"name": "Blue T-Shirt",
"product_id": 43,
"variation_id": 0,
"quantity": 1,
"subtotal": "9.00",
"subtotal_tax": "0.72",
"total": "9.00",
"total_tax": "0.72",
"taxes": [
{
"id": 1,
"total": "0.72",
"subtotal": "0.72"
}
],
"meta_data": [
{
"id": 21643,
"key": "_order_item_wh",
"value": "204"
}

Querying orders over REST API - and filtering by warehouse

wp-json/wc/v3/orders?status=processing&warehouse=204

When using the default WooCommerce REST API to query orders, a filter by warehouse can also be added to only return orders assigned to a specific warehouse - per the example above.

Was this article helpful?
0 out of 1 found this helpful

Navigation