跳到主要内容
将当前页面内容以 Markdown 格式复制到剪贴板

产品评论

The product reviews API allows you to create, view, update, and delete individual, or a batch, of product reviews.

Product review properties

AttributeTypeDescription
idintegerUnique identifier for the resource. READ-ONLY
date_createdstringThe date the review was created, in the site's timezone. READ-ONLY
date_created_gmtstringThe date the review was created, as GMT. READ-ONLY
product_idintegerUnique identifier for the product that the review belongs to.
statusstringStatus of the review. Options: approved, hold, spam, unspam, trash and untrash. Defaults to approved.
reviewerstringReviewer name.
reviewer_emailstringReviewer email.
reviewstringThe content of the review.
ratingintegerReview rating (0 to 5).
verifiedbooleanShows if the reviewer bought the product or not.

Create a product review

This API helps you to create a new product review.

POST /wp-json/wc/v3/products/reviews

创建产品评价的例子:

curl -X POST https://example.com/wp-json/wc/v3/products/reviews \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"product_id": 22,
"review": "Nice album!",
"reviewer": "John Doe",
"reviewer_email": "john.doe@example.com",
"rating": 5
}'

获取产品评价

此 API 允许您通过编号获取产品的评价。

GET /wp-json/wc/v3/products/reviews/<id>
curl https://example.com/wp-json/wc/v3/products/reviews/22 \
-u consumer_key:consumer_secret

查看所有产品评价

此 API 允许您检索所有产品评价。

GET /wp-json/wc/v3/products/reviews
curl https://example.com/wp-json/wc/v3/products/reviews \
-u consumer_key:consumer_secret

可用的参数

ParameterTypeDescription
contextstringScope under which the request is made; determines fields present in response. Options: view and edit. Default is view.
pageintegerCurrent page of the collection. Default is 1.
per_pageintegerMaximum number of items to be returned in result set. Default is 10.
searchstringLimit results to those matching a string.
afterstringLimit response to reviews published after a given ISO8601 compliant date.
beforestringLimit response to reviews published before a given ISO8601 compliant date.
dates_are_gmtbooleanInterpret after and before as UTC dates when true.
excludearrayEnsure result set excludes specific ids.
includearrayLimit result set to specific ids.
offsetintegerOffset the result set by a specific number of items.
orderstringOrder sort attribute ascending or descending. Options: asc and desc. Default is desc.
orderbystringSort collection by resource attribute. Options: date, date_gmt, id, slug, include and product. Default is date_gmt.
reviewerarrayLimit result set to reviews assigned to specific user IDs.
reviewer_excludearrayEnsure result set excludes reviews assigned to specific user IDs.
reviewer_emailarrayLimit result set to that from a specific author email.
productarrayLimit result set to reviews assigned to specific product IDs.
statusstringLimit result set to reviews assigned a specific status. Options: all, hold, approved, spam and trash. Default is approved.

更新产品评价

此 API 允许您对产品评价进行更改。

PUT /wp-json/wc/v3/products/reviews/<id>
curl -X PUT https://example.com/wp-json/wc/v3/products/reviews/20 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"rating": 5
}'

删除产品评价

此 API 帮助您删除产品评价。

DELETE /wp-json/wc/v3/products/reviews/<id>
curl -X DELETE https://example.com/wp-json/wc/v3/products/reviews/34?force=true \
-u consumer_key:consumer_secret

可用参数

参数类型描述
force字符串必须为 true,因为资源不支持放入回收站。

批量更新产品评价

此 API 可以帮助您批量创建、更新和删除多个产品评价。

备注

注意:默认情况下,限制为最多可以创建、更新或删除 100 个对象。

POST /wp-json/wc/v3/products/reviews/batch
curl -X POST https://example.com/wp-json/wc/v3/products/reviews/batch \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"create": [
{
"product_id": 22,
"review": "Looks fine",
"reviewer": "John Doe",
"reviewer_email": "john.doe@example.com",
"rating": 4
},
{
"product_id": 22,
"review": "I love this album",
"reviewer": "John Doe",
"reviewer_email": "john.doe@example.com",
"rating": 5
}
],
"update": [
{
"id": 7,
"reviewer": "John Doe",
"reviewer_email": "john.doe@example.com"
}
],
"delete": [
22
]
}'