WooCommerce REST API 通过 ID 获取多个产品 [英] WooCommerce REST API GET multiple products by ID

查看:40
本文介绍了WooCommerce REST API 通过 ID 获取多个产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按列表中的每个产品显示所有相关产品.

I need to display all related products by eah product I have in my list.

例如,在我的应用程序中,我有 3 个产品,ID 为 1、2、3产品 id 1 有 5、6、7 作为相关,产品 id 2 有相关的 8 和 9 等.

Eg, In my app I have 3 products with id 1, 2, 3 product id 1 has 5,6,7 as related, product id 2 with related 8 and 9 etc..

现在我有一个包含所有相关 [5,6,7,8,9..] 的数组我怎样才能从 REST API 中只获取这些?

Now I have an array with all the related [5,6,7,8,9..] How can I get only this ones from REST API?

我可以像这样通过单个 ID 调用 site.com/wp-json/wc/v2/products/5/

I can call by single ID like that site.com/wp-json/wc/v2/products/5/

但不适用于多个 ID,例如 ../products/5/6/../products/5,6/

But doesn't work with multiple IDs like ../products/5/6/ or ../products/5,6/

这可能吗?

推荐答案

您可以使用参数 'include' 来实现,如下所示:

you could use parameter 'include' to achieve that like below :

site.com/wp-json/wc/v2/products/?include=5,6,7,8,9

这会将结果限制为特定 ID.

This will limit results to specific Id's.

这篇关于WooCommerce REST API 通过 ID 获取多个产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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