The WooCommerce Customers API allows you to manage customer data within your WooCommerce store. This guide covers how to create, update, retrieve, and delete customer records, as well as how to search and filter customers based on various criteria.
The most common operations people perform on customers using the WooCommerce API.
Action | HTTP Method | Endpoint |
---|---|---|
Create a Customer
|
POST
|
/customers
|
List All Customers
|
GET
|
/customers
|
Retrieve a Customer
|
GET
|
/customers/{customerId}
|
Update a Customer
|
PUT
|
/customers/{customerId}
|
Delete a Customer
|
DELETE
|
/customers/{customerId}
|
Customers in WooCommerce represent individuals or entities who have registered or purchased from your store. Managing customers effectively is crucial for maintaining relationships and driving sales.
Customers are identified by a unique integer ID, which is used to retrieve, update, or delete specific customer records.
To create a customer, you need to provide at least an email address and a password. Additional fields like first name, last name, and username can also be included.
Customers can be searched using various query parameters such as email, role, and search terms. You can also filter by specific IDs or exclude certain IDs from the results.
The properties section lists the key attributes of a customer object in WooCommerce. These properties are essential for managing customer data effectively. Show all properties Only show essential properties
Field Name | Type | Short Description |
---|---|---|
id | integer | Unique identifier for the resource. |
string | The email address for the customer. Mandatory. | |
first_name | string | Customer first name. |
last_name | string | Customer last name. |
username | string | Customer login name. |
date_created | datetime | The date the customer was created, in the site's timezone. |
date_modified | datetime | The date the customer was last modified, in the site's timezone. |
is_paying_customer | boolean | Is the customer a paying customer? |
avatar_url | string | Avatar URL. |
date_created_gmt | datetime | The date the customer was created, as GMT. |
date_modified_gmt | datetime | The date the customer was last modified, as GMT. |
role | string | Customer role. |
password | string | Customer password. Write-only. |
billing | object | Billing address details. |
shipping | object | Shipping address details. |
meta_data | array | Meta data associated with the customer. |
The WooCommerce Customers API supports a variety of filtering options to help you retrieve specific customer records based on your criteria.
Parameter | Type | Description | Example |
---|---|---|---|
context
|
string | Scope under which the request is made; determines fields present in response. |
context=view
|
email
|
string | Limit result set to resources with a specific email. |
email=user@example.com
|
exclude
|
array | Ensure result set excludes specific IDs. |
exclude=1,2,3
|
include
|
array | Limit result set to specific IDs. |
include=4,5,6
|
offset
|
integer | Offset the result set by a specific number of items. |
offset=10
|
order
|
string | Order sort attribute ascending or descending. |
order=asc
|
orderby
|
string | Sort collection by object attribute. |
orderby=name
|
page
|
integer | Current page of the collection. |
page=2
|
per_page
|
integer | Maximum number of items to be returned in result set. |
per_page=20
|
role
|
string | Limit result set to resources with a specific role. |
role=customer
|
search
|
string | Limit results to those matching a string. |
search=John
|
When working with the WooCommerce Customers API, there are a few important considerations to keep in mind to avoid common pitfalls.
Each customer must have a unique email
address. Attempting to create or update a customer with an existing email will result in an error.
The password
field is write-only and cannot be retrieved once set. Ensure you store passwords securely and handle them with care.
The role
field is read-only and defaults to customer
unless specified otherwise during creation. Roles determine the customer's permissions within WooCommerce.
Here are some frequently asked questions about the WooCommerce Customers API and how to manage customer data effectively.
GET /customers
endpoint with the email
query parameter. For example, /customers?email=user@example.com
will return the customer with the specified email.
PUT /customers/{customerId}
endpoint, the customer's details are modified as per the provided data. Ensure that you provide only the fields you wish to update.
DELETE /customers/{customerId}
endpoint. However, you must set the force
parameter to true
as WooCommerce does not support trashing customers.
customer
, but you can specify other roles if needed. Note that roles are read-only after creation.
email
, role
, search
, include
, and exclude
. These parameters allow you to filter and refine your search results effectively.