WooCommerce REST API - Get Custom Fields for Order

2019-05-15 04:56发布

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.

1条回答
做自己的国王
2楼-- · 2019-05-15 05:39

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

查看更多
登录 后发表回答