WooCommerce REST API - Get Custom Fields for Order

天涯浪子 提交于 2019-12-22 10:19:13

问题


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:


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



来源:https://stackoverflow.com/questions/42100572/woocommerce-rest-api-get-custom-fields-for-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!