PHP Class WC_API_Customers

Inheritance: extends WC_API_Resource
Exibir arquivo Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$base string the route base

Public Methods

Method Description
__construct ( WC_API_Server $server ) : WC_API_Customers Setup class, overridden to provide customer data to order response
add_customer_data ( $order_data, $order ) : array Add customer data to orders
bulk ( array $data ) : array Bulk update or insert customers Accepts an array with customers in the formats supported by WC_API_Customers->create_customer() and WC_API_Customers->edit_customer()
create_customer ( array $data ) : array Create a customer
delete_customer ( integer $id ) : array Delete a customer
edit_customer ( integer $id, array $data ) : array Edit a customer
get_customer ( integer $id, array $fields = null ) : array Get the customer for the given ID
get_customer ( integer $id, string $fields = null ) : array Get the customer for the given ID
get_customer_by_email ( string $email, array $fields = null ) : array Get the customer for the given email
get_customer_downloads ( integer $id, string $fields = null ) : array Get the available downloads for a customer
get_customer_orders ( integer $id, string $fields = null ) : array Get the orders for a customer
get_customer_orders ( integer $id, string $fields = null, array $filter = [] ) : array Get the orders for a customer
get_customers ( array $fields = null, array $filter = [], integer $page = 1 ) : array Get all customers
get_customers_count ( array $filter = [] ) : array Get the total number of customers
modify_user_query ( WP_User_Query $query ) Modify the WP_User_Query to support filtering on the date the customer was created
register_routes ( array $routes ) : array Register the routes for this class

Protected Methods

Method Description
get_customer_billing_address ( ) : array Get customer billing address fields.
get_customer_shipping_address ( ) : array Get customer shipping address fields.
is_readable ( integer | WP_Post $post ) : boolean Check if the current user can read users
update_customer_data ( integer $id, array $data, WC_Customer $customer ) Add/Update customer data.
validate_request ( integer $id, string $type, string $context ) : integer | WP_Error Validate the request by checking:
validate_request ( string | integer $id, string $type, string $context ) : integer | WP_Error Validate the request by checking:

Private Methods

Method Description
query_customers ( array $args = [] ) : WP_User_Query Helper method to get customer user objects

Method Details

__construct() public method

Setup class, overridden to provide customer data to order response
Since: 2.1
public __construct ( WC_API_Server $server ) : WC_API_Customers
$server WC_API_Server
return WC_API_Customers

add_customer_data() public method

Add customer data to orders
Since: 2.1
public add_customer_data ( $order_data, $order ) : array
$order_data
$order
return array

bulk() public method

Bulk update or insert customers Accepts an array with customers in the formats supported by WC_API_Customers->create_customer() and WC_API_Customers->edit_customer()
Since: 2.4.0
public bulk ( array $data ) : array
$data array
return array

create_customer() public method

Create a customer
Since: 2.2
public create_customer ( array $data ) : array
$data array
return array

delete_customer() public method

Delete a customer
Since: 2.2
public delete_customer ( integer $id ) : array
$id integer the customer ID
return array

edit_customer() public method

Edit a customer
Since: 2.2
public edit_customer ( integer $id, array $data ) : array
$id integer the customer ID
$data array
return array

get_customer() public method

Get the customer for the given ID
Since: 2.1
public get_customer ( integer $id, array $fields = null ) : array
$id integer the customer ID
$fields array
return array

get_customer() public method

Get the customer for the given ID
Since: 2.1
public get_customer ( integer $id, string $fields = null ) : array
$id integer the customer ID
$fields string
return array

get_customer_billing_address() protected method

Get customer billing address fields.
Since: 2.2
protected get_customer_billing_address ( ) : array
return array

get_customer_by_email() public method

Get the customer for the given email
Since: 2.1
public get_customer_by_email ( string $email, array $fields = null ) : array
$email string the customer email
$fields array
return array

get_customer_downloads() public method

Get the available downloads for a customer
Since: 2.2
public get_customer_downloads ( integer $id, string $fields = null ) : array
$id integer the customer ID
$fields string fields to include in response
return array

get_customer_orders() public method

Get the orders for a customer
Since: 2.1
public get_customer_orders ( integer $id, string $fields = null ) : array
$id integer the customer ID
$fields string fields to include in response
return array

get_customer_orders() public method

Get the orders for a customer
Since: 2.1
public get_customer_orders ( integer $id, string $fields = null, array $filter = [] ) : array
$id integer the customer ID
$fields string fields to include in response
$filter array filters
return array

get_customer_shipping_address() protected method

Get customer shipping address fields.
Since: 2.2
protected get_customer_shipping_address ( ) : array
return array

get_customers() public method

Get all customers
Since: 2.1
public get_customers ( array $fields = null, array $filter = [], integer $page = 1 ) : array
$fields array
$filter array
$page integer
return array

get_customers_count() public method

Get the total number of customers
Since: 2.1
public get_customers_count ( array $filter = [] ) : array
$filter array
return array

is_readable() protected method

Check if the current user can read users
See also: WC_API_Resource::is_readable()
Since: 2.1
protected is_readable ( integer | WP_Post $post ) : boolean
$post integer | WP_Post unused
return boolean true if the current user can read users, false otherwise

modify_user_query() public method

Modify the WP_User_Query to support filtering on the date the customer was created
Since: 2.1
public modify_user_query ( WP_User_Query $query )
$query WP_User_Query

register_routes() public method

GET /customers GET /customers/count GET /customers/ GET /customers//orders
Since: 2.2
public register_routes ( array $routes ) : array
$routes array
return array

update_customer_data() protected method

Add/Update customer data.
Since: 2.2
protected update_customer_data ( integer $id, array $data, WC_Customer $customer )
$id integer the customer ID
$data array
$customer WC_Customer

validate_request() protected method

1) the ID is a valid integer 2) the ID returns a valid WP_User 3) the current user has the proper permissions
See also: WC_API_Resource::validate_request()
Since: 2.1
protected validate_request ( integer $id, string $type, string $context ) : integer | WP_Error
$id integer the customer ID
$type string the request type, unused because this method overrides the parent class
$context string the context of the request, either `read`, `edit` or `delete`
return integer | WP_Error valid user ID or WP_Error if any of the checks fails

validate_request() protected method

1) the ID is a valid integer 2) the ID returns a valid WP_User 3) the current user has the proper permissions
See also: WC_API_Resource::validate_request()
Since: 2.1
protected validate_request ( string | integer $id, string $type, string $context ) : integer | WP_Error
$id string | integer the customer ID
$type string the request type, unused because this method overrides the parent class
$context string the context of the request, either `read`, `edit` or `delete`
return integer | WP_Error valid user ID or WP_Error if any of the checks fails

Property Details

$base protected_oe property

the route base
protected string $base
return string