WooCommerce API - 更新订单元字段 [英] WooCommerce API - Update Order Meta Fields

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

问题描述

WooCommerce Rest API 是否提供任何更新元字段的方法?

他们有一个扩展,可以在使用元字段发货时向订单添加跟踪号,但没有任何关于如何或是否可以通过他们的 REST 使用此信息更新订单元字段的文档API.

解决方案

2020 更新:

最新版本的 WooCommerce API 允许更新以下划线开头的元字段.耶!您可以像下面提到的 big_water 那样批量执行此操作:https://stackoverflow.com/a/44661445/137695>

您还可以使用新的 V2 或 V3 WooCommerce API Order Update PUT 端点更新单个订单的元字段:https://woocommerce.github.io/woocommerce-rest-api-docs/#update-an-order

"meta_data": [{"key": "_some_field",价值":一些价值"},{"key": "_some_other_field",价值":其他一些价值"}]

下面的旧答案 - 仅关于旧的 WooCommerce API 端点:

关于如何做到这一点的记录很差(根本没有阅读).以下是对普通元字段执行此操作的方法:

curl -X PUT "https://somesite.com/wc-api/v2/orders/124?filter[meta]=true" -u ck_yourconsumerkey:cs_yourconsumersecret -H "Content-Type: application/json" -d'{命令": {order_meta":{meta_key":meta_value"}}}'

以下划线开头的元字段受到保护,无法通过 API 更新.但是,根据 this GitHub issue,WooCommerce 的下一版本应该支持更新受保护的元字段只要它们不是 WooCommerce 内部值.

订单的其他部分(例如客户和商品)有元字段,但我需要一段时间才能再次挖掘这些信息,而这个问题专门针对订单级别的元字段.

WooCommerce 改变了主意并关闭了 GitHub 案例,表示他们将不允许访问这些字段.不幸的是,这使 WooCommerce 成为唯一无法通过 API 向订单添加跟踪信息的购物车之一,而没有可怕的黑客解决方法.

Does the WooCommerce Rest API offer any way to update meta fields?

They have an Extension which adds the ability to add tracking numbers to an order when it's shipped using meta fields, but don't have any documentation on how or if it's possible to update the order's meta fields with this information via their REST API.

解决方案

2020 Update:

The latest versions of the WooCommerce API allow updating meta fields that start with an underscore. Yay! You can do so in bulk as big_water mentioned below: https://stackoverflow.com/a/44661445/137695

You can also update meta fields for a single order using the new V2 or V3 WooCommerce API Order Update PUT endpoint: https://woocommerce.github.io/woocommerce-rest-api-docs/#update-an-order

"meta_data": [
  {
    "key": "_some_field",
    "value": "some value"
  },
  {
    "key": "_some_other_field",
    "value": "some other value"
  }
]

OLD ANSWER BELOW - Regarding the old WooCommerce API endpoints only:

It's poorly (read not at all) documented how to do this. Here's how to do it for normal meta fields:

curl -X PUT "https://somesite.com/wc-api/v2/orders/124?filter[meta]=true" -u ck_yourconsumerkey:cs_yourconsumersecret -H "Content-Type: application/json" -d 
'{
    "order": {
        "order_meta": {"meta_key":"meta_value"}
    }
}'

Meta fields that start with an underscore are protected and cannot be updated via the API. However, according to this GitHub issue the next version of WooCommerce should support updating protected meta fields as long as they aren't WooCommerce internal values.

There are Meta fields for other parts of the order like customer and item, but it would take me a while to dig up info on those again and this question was specifically regarding Order level meta fields.

Edit: WooCommerce has changed their minds and closed the GitHub case saying they will not allow access to these fields. This unfortunately makes WooCommerce one of the only shopping carts where it is impossible to add tracking information to an order via the API without a terrible hackish workaround.

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

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