Woocommerce REST API - 添加自定义路由 [英] Woocommerce REST API - Add custom routes
问题描述
我有一家 Woocommerce 商店,我正在使用 Woocommerce REST API 在另一个网站上列出产品等,并且工作正常.不过,我缺少一些功能,我想知道是否可以通过自定义调用来扩展 API?
I have a Woocommerce shop and I'm using the Woocommerce REST API to list products etc. on another site and it works fine. There are some functionality that I'm missing though, and I'm wondering if it is possible to extend the API with custom calls?
推荐答案
通过阅读 Woocommerce 的源代码,我能够弄清楚如何做到这一点.
I was able to figure out how to this by reading the source code for Woocommerce.
首先,我必须创建一个扩展 WC_API_Resource 的类,并在该类的 register_routes 方法中添加我的路由.然后我必须通过将类添加到 woocommerce_api_classes 过滤器中的类数组来确保 Woocommerce 将此类添加到 API.
First I had to create a class that extends WC_API_Resource and add my routes in the register_routes method of this class. Then I had to make sure that Woocommerce adds this class to the API by adding the class to the class-array in the woocommerce_api_classes filter.
这篇关于Woocommerce REST API - 添加自定义路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!