WooCommerce REST API 文档

title: "退款 #" post_status: publish comment_status: open taxonomy: category: - woocommerce-rest-api post_tag: - Wp Api V3 - Includes - Source


退款

退款 API 是一个简单的只读端点,允许您在现有订单上下文之外检索退款列表。如需创建、查看和删除单个退款,请查阅订单退款 API

退款属性

所有属性均与订单退款端点中的属性相同,但额外增加了一个属性:

属性 类型 描述
parent_id integer 此退款关联的订单 ID。

获取退款列表

此 API 允许您检索和查看商店中的退款,无论它们与哪个订单相关联。

HTTP 请求

GET
/wp-json/wc/v3/refunds
curl https://example.com/wp-json/wc/v3/refunds \
    -u consumer_key:consumer_secret
WooCommerce.get("refunds")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php print_r($woocommerce->get('refunds')); ?>
print(wcapi.get("refunds").json())
woocommerce.get("refunds").parsed_response

JSON 响应示例:

[
    {
        "id": 726,
        "parent_id": 124,
        "date_created": "2017-03-21T17:07:11",
        "date_created_gmt": "2017-03-21T20:07:11",
        "amount": "10.00",
        "reason": "",
        "refunded_by": 1,
        "refunded_payment": false,
        "meta_data": [],
        "line_items": [],
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc/v3/orders/723/refunds/726"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc/v3/orders/723/refunds"
                }
            ],
            "up": [
                {
                    "href": "https://example.com/wp-json/wc/v3/orders/723"
                }
            ]
        }
    },
    {
        "id": 724,
        "parent_id": 63,
        "date_created": "2017-03-21T16:55:37",
        "date_created_gmt": "2017-03-21T19:55:37",
        "amount": "9.00",
        "reason": "",
        "refunded_by": 1,
        "refunded_payment": false,
        "meta_data": [],
        "line_items": [
            {
                "id": 314,
                "name": "Woo Album #2",
                "product_id": 87,
                "variation_id": 0,
                "quantity": -1,
                "tax_class": "",
                "subtotal": "-9.00",
                "subtotal_tax": "0.00",
                "total": "-9.00",
                "total_tax": "0.00",
                "taxes": [],
                "meta_data": [
                    {
                        "id": 2076,
                        "key": "_refunded_item_id",
                        "value": "311"
                    }
                ],
                "sku": "",
                "price": -9
            }
        ],
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc/v3/orders/723/refunds/724"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc/v3/orders/723/refunds"
                }
            ],
            "up": [
                {
                    "href": "https://example.com/wp-json/wc/v3/orders/723"
                }
            ]
        }
    }
]

Available parameters

Parameter Type Description
context string Scope under which the request is made; determines fields present in response. Options: view and edit. Default is view.
page integer Current page of the collection. Default is 1.
per_page integer Maximum number of items to be returned in result set. Default is 10.
search string Limit results to those matching a string.
after string Limit response to resources published after a given ISO8601 compliant date.
before string Limit response to resources published before a given ISO8601 compliant date.
exclude array Ensure result set excludes specific IDs.
include array Limit result set to specific ids.
offset integer Offset the result set by a specific number of items.
order string Order sort attribute ascending or descending. Options: asc and desc. Default is desc.
orderby string Sort collection by object attribute. Options: date, modified, id, include, title and slug. Default is date.
parent array Limit result set to those of particular parent IDs.
parent_exclude array Limit result set to all items except those of a particular parent ID.
dp integer Number of decimal points to use in each resource. Default is 2.