如何从woocommerce中的特定类别获取所有产品?

时间:2018-07-12 10:38:52

标签: woocommerce woocommerce-rest-api

我正在使用node.js。我想通过 woocomerce api 获得属于特定类别的产品。

我无法修改/添加新的php代码,因为该程序已由非程序员使用。他们应该只是在输入字段中插入秘密和密钥,然后我用它们开始以编程方式查询他们的商店。

所以类似这样的问题:Get Products by Product category in a shortcode with WooCommerce似乎不适用于我。

我有兴趣知道我需要点击哪个特定的URL端点,以便可以从给定类别中获取所有产品。

尝试:

https://ecom.pssthemes.com/woocommerce/wp-json/wc/v2/products?consumer_key=key&consumer_secret=secret&filter[product_cat]="decor"

https://ecom.pssthemes.com/woocommerce/wp-json/wc/v2/products?consumer_key=key&consumer_secret=secret&filter[category]="decor"

以及lib:

WooCommerce.get('products?filter[category]="decor"', function(err, data, res) {
  console.log(res);
});

没有任何工作。这似乎是一项基本要求。我在这里错过明显的东西吗?任何解决问题的见解都将受到赞赏。谢谢:)

1 个答案:

答案 0 :(得分:0)

尝试以下代码,将category id替换为所需类别的ID:

WooCommerce.getAsync('products?category=<category id>).then( (data) => {
    console.log(JSON.parse(data.body));
}, (err) => {
    console.log(err)
})
相关问题