如何从WooCommerce产品CRUD webhook获取正确的数据?

时间:2017-06-13 12:56:52

标签: wordpress woocommerce

我正在创建一个能够从许多WooCommerce网站接收网络连接的系统。

我还创建了一堆WooCommerce实例,并将其配置为每当产品CRUD操作发生时都将此地址https://requestb.in/qivtf4qi挂起。

但是,当对某个WooCommerce实例中的产品执行CRUD操作时,webhook内容似乎不正确:

  • 它不包含任何有效负载,
  • 它没有任何方法可以识别webhook的来源(实例域等),除了原始服务器IP(如果实例移动或水平移动,则相当不可靠)。

让WooCommerce提供正确的 webhook数据的正确方法是什么?

See an example of what gets sent on product update: no way to identify the instance, no content so quite pointless as we would have to query all the products to find out which one was updated

See how each WooCommerce instance is configured to deliver hooks to that single service we're building.

See how the WooCommerce API docs say that the webhook payload should actually carry the resource like if it was modified using the REST API. They also mention a header, X-WC-Webhook-Source, that should contain the source domain.

1 个答案:

答案 0 :(得分:0)

我发现要发送webhooks需要两件事(WooCommerce docs未知):

  • 必须安装并启用CURL PHP扩展。
  • webhooks由Wordpress cron作业(site.Bindings.Add(httpsBindingInformation, httpsProtocol);)提供,在我们的开发环境中它没有设置。

正如this issue中所建议的,检查每个webhook日志也有帮助,因为空日志表明设置中存在问题,如前所述(CURL / Cron等)。