WooCommerce API 列出具有特定属性的所有产品
使用 WooCommerce API,我想发送 HTTP GET 请求以下载具有特定属性的所有产品.
Using the WooCommerce API I want to send an HTTP GET request to download all products with a specific attribute.
文档 说要使用的 URL 是这个
The documentation says the URL to do this with is this
/wp-json/wc/v3/products
我可以向 URL 添加参数以过滤产品.
And I can add parameters to the URL in order to filter the products.
我已成功为页面和页面计数添加过滤器:
I have successfully added filters for page and page count:
wp-json/wc/v3/products?per_page=100&page=10
我还设法仅获得具有此参数的可用产品:
I have also managed to get only available products with this parameter:
wp-json/wc/v3/products?&stock_status=instock
但是,我无法为属性添加过滤器.我尝试了以下方法来编写 URL,但它们都不起作用
However, I cannot manage to add a filter for the attributes. I have tried the following ways to write the URL and non of them work
wp-json/wc/v3/products/?attribute=1
wp-json/wc/v3/products/?
wp-json/wc/v3/products/?attribute_pa_емаг=Да
wp-json/wc/v3/products/?filter[pa_емаг]=10
写 URL 的正确方法是什么?
What would be the correct way to write the URL?
(注:属性为pa_емаг,值为Да)
(Note: The attribute is pa_емаг and its value is Да)
正确的调用应该是:
/wp-json/wc/v3/products?attribute={attribute-taxonomy}&attribute_term={term-id/tag_ID}
在您的情况下,attribute-taxonomy 将是完整的 slug,而 term-id/tag_ID 是Да"的 id.
Where attribute-taxonomy would be full slug in your case "pa_емаг", and term-id/tag_ID the id of "Да".