Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce REST API - Get Custom Fields for Order

I'm using the WooCommerce REST API (http://woocommerce.github.io/woocommerce-rest-api-docs/#introduction) and are able to download Customers, Orders etc successfully.

My customer has added some custom fields to the checkout page, e.g.:

po_number
accounts_email

I would like to be able to GET these custom fields when requesting an ORDER, e.g.:

/wp-json/wc/v1/orders/4568

At the moment none of the custom fields are returned when I GET an Order. I've tried adding

?filter[meta]=true

to the request URL but that doesn't make any difference. Is there a way I can modify the GET URL to include all custom fields? Couldn't find any reference in the REST API docs to custom fields.

like image 853
user982124 Avatar asked Sep 13 '25 13:09

user982124


1 Answers

I have struggled like you did, but then it turns out using the newer v2 REST API solves the issue for me. So instead of:

/wp-json/wc/v1/orders/4568

I now use:

/wp-json/wc/v2/orders/4568

And custom fields will be included in the response with the key meta_data, even with those hidden fields starting with _.

like image 118
whitmenn Avatar answered Sep 16 '25 08:09

whitmenn