'Add tracking info into WooCommerce order via Rest API
I'm trying to update a WooCommerce order using Update an Order in the Woo API (API Doc)
I want to add the following information into an order:
- tracking provider
- tracking number
- tracking URL
I can add/update information inside of the "meta data" array, however, I can't seem to figure out how to update the "_wc_shipment_tracking_items" "value" array that is located within the "meta data" array.
So essentially, I want to update/create an array within an array. For a visual understanding, see (highlighted is where I want to update):
I’ve tried many variations, but the following is as far as I've come... I can’t seem to figure it out:
"meta_data": [
{
"key": "_wc_shipment_tracking_items"
"value": [
{
"key": "custom_tracking_provider",
"value": "postage service"
},
{
"key": "tracking_number",
"value": "aaa123"
},
{
"key": "custom_tracking_link",
"value": "https://google.com/"
}
]
}
]
I hope someone can help me out, or point me in the right direction. Thank you :)
Solution 1:[1]
The answer to your question can be found on this page: https://woocommerce.com/document/shipment-tracking/
under 'REST API Support' you will find this piece of code that you need:
curl -X POST https://example.com/wp-json/wc-shipment-tracking/v3/orders/645/shipment-trackings \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"custom_tracking_provider": "Custom",
"custom_tracking_link": "https://example.com?q=%1$s",
"tracking_number": "12345678"
}'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Danielle |

