WooCommerce REST API 文档

title: "订单备注 #" post_status: publish comment_status: open taxonomy: category: - woocommerce-rest-api post_tag: - Wp Api V1 - Includes - Source


订单备注

订单备注 API 允许您创建、查看和删除单个订单备注。
订单备注由管理员或通过程序添加,用于存储订单或订单事件的相关数据。

Order note properties

Attribute Type Description
id integer Unique identifier for the resource. read-only
date_created date-time The date the order note was created, in the site's timezone. read-only
note string Order note. required
customer_note boolean Shows/define if the note is only for reference or for the customer (the user will be notified). Default is false.

创建订单备注

此 API 帮助您为订单创建新的备注。

HTTP 请求

POST
/wp-json/wc/v1/orders/<id>/notes
curl -X POST https://example.com/wp-json/wc/v1/orders/645/notes \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "note": "Order ok!!!"
}'
const data = {
  note: "Order ok!!!"
};

WooCommerce.post("orders/645/notes", data)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php
$data = [
    'note' => 'Order ok!!!'
];

print_r($woocommerce->post('orders/645/notes', $data));
?>
data = {
    "note": "Order ok!!!"
}

print(wcapi.post("orders/645/notes", data).json())
data = {
  note: "Order ok!!!"
}

woocommerce.post("orders/645/notes", data).parsed_response

JSON 响应示例:

{
  "id": 51,
  "date_created": "2016-05-13T20:51:55",
  "note": "Order ok!!!",
  "customer_note": false,
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/118/notes/51"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/118/notes"
      }
    ],
    "up": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/118"
      }
    ]
  }
}

获取订单备注

此 API 允许您检索和查看订单中的特定备注。

HTTP 请求

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

JSON 响应示例:

{
  "id": 51,
  "date_created": "2016-05-13T20:51:55",
  "note": "Order ok!!!",
  "customer_note": false,
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/118/notes/51"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/118/notes"
      }
    ],
    "up": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/118"
      }
    ]
  }
}

列出所有订单备注

此 API 可帮助您查看订单中的所有备注。

HTTP 请求

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

JSON 响应示例:

[
  {
    "id": 51,
    "date_created": "2016-05-13T20:51:55",
    "note": "Order ok!!!",
    "customer_note": false,
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/118/notes/51"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/118/notes"
        }
      ],
      "up": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/118"
        }
      ]
    }
  },
  {
    "id": 46,
    "date_created": "2016-05-03T18:10:43",
    "note": "Order status changed from Pending Payment to Processing.",
    "customer_note": false,
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/118/notes/46"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/118/notes"
        }
      ],
      "up": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/118"
        }
      ]
    }
  }
]

删除订单备注

此 API 可帮助您删除订单备注。

HTTP 请求

DELETE
/wp-json/wc/v1/orders/<id>/notes/<note_id>
curl -X DELETE https://example.com/wp-json/wc/v1/orders/645/notes/51?force=true \
    -u consumer_key:consumer_secret
WooCommerce.delete("orders/645/notes/51", {
  force: true
})
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php print_r($woocommerce->delete('orders/645/notes/51', ['force' => true])); ?>
print(wcapi.delete("orders/645/notes/51", params={"force": True}).json())
woocommerce.delete("orders/645/notes/51", force: true).parsed_response

JSON 响应示例:

{
  "id": 51,
  "date_created": "2016-05-13T20:51:55",
  "note": "Order ok!!!",
  "customer_note": false,
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/118/notes/51"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/118/notes"
      }
    ],
    "up": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/118"
      }
    ]
  }
}

Available parameters

Parameter Type Description
force string Required to be true, as resource does not support trashing.