购物车优惠券 API
获取购物车优惠券列表
GET /cart/coupons
此接口不需要任何参数。
curl "https://example-store.com/wp-json/wc/store/v1/cart/coupons"
示例响应:
[
{
"code": "20off",
"type": "fixed_cart",
"totals": {
"currency_code": "GBP",
"currency_symbol": "£",
"currency_minor_unit": 2,
"currency_decimal_separator": ".",
"currency_thousand_separator": ",",
"currency_prefix": "£",
"currency_suffix": "",
"total_discount": "1667",
"total_discount_tax": "333"
},
"_links": {
"self": [
{
"href": "http://local.wordpress.test/wp-json/wc/store/v1/cart/coupons/20off"
}
],
"collection": [
{
"href": "http://local.wordpress.test/wp-json/wc/store/v1/cart/coupons"
}
]
}
}
]
获取单个购物车优惠券
获取单个购物车优惠券。
GET /cart/coupons/:code
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
code | 字符串 | 是 | 要检索的购物车优惠券的优惠券代码。 |
curl "https://example-store.com/wp-json/wc/store/v1/cart/coupons/20off"
示例响应:
{
"code": "halfprice",
"type": "percent",
"totals": {
"currency_code": "GBP",
"currency_symbol": "£",
"currency_minor_unit": 2,
"currency_decimal_separator": ".",
"currency_thousand_separator": ",",
"currency_prefix": "£",
"currency_suffix": "",
"total_discount": "9950",
"total_discount_tax": "0"
}
}
添加购物车优惠券
将优惠券应用于购物车。 如果成功应用,则返回新的优惠券对象;否则,返回错误。
POST /cart/coupons/
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
code | 字符串 | 是 | 您希望应用于购物车的优惠券代码。 |
curl --request POST https://example-store.com/wp-json/wc/store/v1/cart/coupons?code=20off
示例响应:
{
"code": "20off",
"type": "percent",
"totals": {
"currency_code": "GBP",
"currency_symbol": "£",
"currency_minor_unit": 2,
"currency_decimal_separator": ".",
"currency_thousand_separator": ",",
"currency_prefix": "£",
"currency_suffix": "",
"total_discount": "1667",
"total_discount_tax": "333"
}
}
删除单个购物车优惠券
删除/移除购物车中的优惠券。
DELETE /cart/coupons/:code
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
code | 字符串 | 是 | 您希望从购物车中移除的优惠券代码。 |
curl --request DELETE https://example-store.com/wp-json/wc/store/v1/cart/coupons/20off
删除购物车中的所有优惠券
删除/移除购物车中的所有优惠券。
DELETE /cart/coupons/
这个接口不需要任何参数。
curl --request DELETE https://example-store.com/wp-json/wc/store/v1/cart/coupons
例子回复:
[]