WooCommerce REST API - 获取订单的自定义字段 [英] WooCommerce REST API - Get Custom Fields for Order

查看:88
本文介绍了WooCommerce REST API - 获取订单的自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WooCommerce REST API(http://woocommerce.github.io/woocommerce-rest-api-docs/#introduction) 并且能够成功下载客户、订单等.

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

到请求 URL,但这没有任何区别.有没有办法修改 GET URL 以包含所有自定义字段?在 REST API 文档中找不到任何对自定义字段的引用.

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.

推荐答案

我和你一样挣扎过,但结果证明使用较新的 v2 REST API 为我解决了这个问题.所以,而不是:

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

我现在使用:

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

并且自定义字段将包含在带有键 meta_data 的响应中,即使是那些以 _ 开头的隐藏字段.

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

这篇关于WooCommerce REST API - 获取订单的自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆