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

客户

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

Customer properties

AttributeTypeDescription
idintegerUnique identifier for the resource. READ-ONLY
date_createddate-timeThe date the customer was created, in the site's timezone. READ-ONLY
date_created_gmtdate-timeThe date the customer was created, as GMT. READ-ONLY
date_modifieddate-timeThe date the customer was last modified, in the site's timezone. READ-ONLY
date_modified_gmtdate-timeThe date the customer was last modified, as GMT. READ-ONLY
emailstringThe email address for the customer. MANDATORY
first_namestringCustomer first name.
last_namestringCustomer last name.
rolestringCustomer role. READ-ONLY
usernamestringCustomer login name.
passwordstringCustomer password. WRITE-ONLY
billingobjectList of billing address data. See Customer - Billing properties
shippingobjectList of shipping address data. See Customer - Shipping properties
is_paying_customerboolIs the customer a paying customer? READ-ONLY
avatar_urlstringAvatar URL. READ-ONLY
meta_dataarrayMeta data. See Customer - Meta data properties

Customer - Billing properties

AttributeTypeDescription
first_namestringFirst name.
last_namestringLast name.
companystringCompany name.
address_1stringAddress line 1
address_2stringAddress line 2
citystringCity name.
statestringISO code or name of the state, province or district.
postcodestringPostal code.
countrystringISO code of the country.
emailstringEmail address.
phonestringPhone number.

Customer - Shipping properties

AttributeTypeDescription
first_namestringFirst name.
last_namestringLast name.
companystringCompany name.
address_1stringAddress line 1
address_2stringAddress line 2
citystringCity name.
statestringISO code or name of the state, province or district.
postcodestringPostal code.
countrystringISO code of the country.

Customer - Meta data properties

AttributeTypeDescription
idintegerMeta ID. READ-ONLY
keystringMeta key.
valuestringMeta value.

创建客户

这个 API 可以帮助您创建新的客户。

POST /wp-json/wc/v3/customers
curl -X POST https://example.com/wp-json/wc/v3/customers \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"email": "john.doe@example.com",
"first_name": "John",
"last_name": "Doe",
"username": "john.doe",
"billing": {
"first_name": "John",
"last_name": "Doe",
"company": "",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US",
"email": "john.doe@example.com",
"phone": "(555) 555-5555"
},
"shipping": {
"first_name": "John",
"last_name": "Doe",
"company": "",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
}
}'

获取客户信息

此 API 允许您通过编号检索并查看特定客户的信息。

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

查看全部客户

此 API 帮助您查看所有客户。

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

Available parameters

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.
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 asc.
orderbystringSort collection by object attribute. Options: id, include, name and registered_date. Default is name.
emailstringLimit result set to resources with a specific email.
rolestringLimit result set to resources with a specific role. Options: all, administrator, editor, author, contributor, subscriber, customer and shop_manager. Default is customer.

Update a customer

This API lets you make changes to a customer.

PUT /wp-json/wc/v3/customers/<id>
curl -X PUT https://example.com/wp-json/wc/v3/customers/25 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"first_name": "James",
"billing": {
"first_name": "James"
},
"shipping": {
"first_name": "James"
}
}'

删除客户

此 API 可帮助您删除一个客户。

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

可用参数

参数类型描述
force字符串必须为 true,因为资源不支持放入回收站。
reassign整数用于重新分配帖子的用户 ID。

批量更新客户

此 API 可帮助您批量创建、更新和删除多个客户。

备注

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

POST /wp-json/wc/v3/customers/batch
curl -X POST https://example.com/wp-json/wc/v3/customers/batch \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"create": [
{
"email": "john.doe2@example.com",
"first_name": "John",
"last_name": "Doe",
"username": "john.doe2",
"billing": {
"first_name": "John",
"last_name": "Doe",
"company": "",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US",
"email": "john.doe@example.com",
"phone": "(555) 555-5555"
},
"shipping": {
"first_name": "John",
"last_name": "Doe",
"company": "",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
}
},
{
"email": "joao.silva2@example.com",
"first_name": "João",
"last_name": "Silva",
"username": "joao.silva2",
"billing": {
"first_name": "João",
"last_name": "Silva",
"company": "",
"address_1": "Av. Brasil, 432",
"address_2": "",
"city": "Rio de Janeiro",
"state": "RJ",
"postcode": "12345-000",
"country": "BR",
"email": "joao.silva@example.com",
"phone": "(55) 5555-5555"
},
"shipping": {
"first_name": "João",
"last_name": "Silva",
"company": "",
"address_1": "Av. Brasil, 432",
"address_2": "",
"city": "Rio de Janeiro",
"state": "RJ",
"postcode": "12345-000",
"country": "BR"
}
}
],
"update": [
{
"id": 26,
"billing": {
"phone": "(11) 1111-1111"
}
}
],
"delete": [
25
]
}'

获取客户下载权限

此 API 允许您检索客户的下载权限。

GET /wp-json/wc/v3/customers/<id>/downloads
curl https://example.com/wp-json/wc/v3/customers/26/downloads \
-u consumer_key:consumer_secret

Customer downloads properties

AttributeTypeDescription
download_idstringDownload ID (MD5). READ-ONLY
download_urlstringDownload file URL. READ-ONLY
product_idintegerDownloadable product ID. READ-ONLY
product_namestringProduct name. READ-ONLY
download_namestringDownloadable file name. READ-ONLY
order_idintegerOrder ID. READ-ONLY
order_keystringOrder key. READ-ONLY
downloads_remainingstringNumber of downloads remaining. READ-ONLY
access_expiresstringThe date when download access expires, in the site's timezone. READ-ONLY
access_expires_gmtstringThe date when download access expires, as GMT. READ-ONLY
fileobjectFile details. READ-ONLY See Customers downloads - File properties

Customer downloads - File properties

AttributeTypeDescription
namestringFile name. READ-ONLY
filestringFile URL. READ-ONLY