WC_Customer
extends WC_Legacy_Customer
in package
Customer class.
Implemented by classes using the same CRUD(s) pattern.
Table of Contents
- $cache_group : string
- Stores meta in cache for future reads.
- $calculated_shipping : string
- Stores if user has calculated shipping in this session.
- $changes : array
- Core data changes for this object.
- $data : array
- Stores customer data.
- $data_store : object
- Contains a reference to the data store for this class.
- $default_data : array
- Set to _data on construct so we can track and reset data if needed.
- $extra_data : array
- Extra data for this object. Name value pairs (name + default value).
- $id : int
- ID for this object.
- $is_vat_exempt : string
- Stores if user is VAT exempt for this session.
- $meta_data : array
- Stores additional meta data.
- $object_read : bool
- This is false until the object is read from the DB.
- $object_type : string
- This is the name of this object type.
- $password : string
- Stores a password if this needs to be changed. Write-only and hidden from _data.
- __clone() : mixed
- When the object is cloned, make sure meta is duplicated correctly.
- __construct() : mixed
- Load customer data based on how WC_Customer is called.
- __get() : string
- __get function.
- __isset() : bool
- __isset legacy.
- __set() : mixed
- __set function.
- __sleep() : array
- Only store the object ID to avoid serializing the data object instance.
- __toString() : string
- Change data to JSON format.
- __wakeup() : mixed
- Re-run the constructor with the object ID.
- add_meta_data() : mixed
- Add meta data.
- apply_changes() : mixed
- Merge changes with data and clear.
- calculated_shipping() : mixed
- Calculated shipping.
- delete() : bool
- Delete an object, set the ID to 0, and return result.
- delete_and_reassign() : bool
- Delete a customer and reassign posts.
- delete_meta_data() : mixed
- Delete meta data.
- delete_meta_data_by_mid() : mixed
- Delete meta data.
- generate_meta_cache_key() : string
- Generate cache key from id and group.
- get_address() : mixed
- Legacy get address.
- get_address_2() : mixed
- Legacy get address 2.
- get_avatar_url() : string
- Return this customer's avatar.
- get_billing() : array
- Get billing.
- get_billing_address() : string
- Get billing_address_1.
- get_billing_address_1() : string
- Get billing_address_1.
- get_billing_address_2() : string
- Get billing_address_2.
- get_billing_city() : string
- Get billing_city.
- get_billing_company() : string
- Get billing_company.
- get_billing_country() : string
- Get billing_country.
- get_billing_email() : string
- Get billing_email.
- get_billing_first_name() : string
- Get billing_first_name.
- get_billing_last_name() : string
- Get billing_last_name.
- get_billing_phone() : string
- Get billing_phone.
- get_billing_postcode() : string
- Get billing_postcode.
- get_billing_state() : string
- Get billing_state.
- get_calculated_shipping() : bool
- Has customer calculated shipping?
- get_changes() : array
- Return data changes only.
- get_city() : mixed
- Legacy get city.
- get_country() : mixed
- Legacy get country.
- get_data() : array
- Returns all data for this object.
- get_data_keys() : array
- Returns array of expected data keys for this object.
- get_data_store() : object
- Get the data store.
- get_date_created() : WC_DateTime|null
- Return the date this customer was created.
- get_date_modified() : WC_DateTime|null
- Return the date this customer was last updated.
- get_default_country() : string
- Get default country for a customer.
- get_default_state() : string
- Get default state for a customer.
- get_display_name() : string
- Return customer's display name.
- get_downloadable_products() : array
- Gets a customer's downloadable products.
- get_email() : string
- Return the customer's email.
- get_extra_data_keys() : array
- Returns all "extra" data keys for an object (for sub objects like product types).
- get_first_name() : string
- Return customer's first name.
- get_id() : int
- Returns the unique ID for this object.
- get_is_paying_customer() : bool
- Is the user a paying customer?
- get_is_vat_exempt() : bool
- Get if customer is VAT exempt?
- get_last_name() : string
- Return customer's last name.
- get_last_order() : WC_Order|false
- Gets the customers last order.
- get_meta() : mixed
- Get Meta Data by Key.
- get_meta_cache_key() : string
- Helper method to compute meta cache key. Different from WP Meta cache key in that meta data cached using this key also contains meta_id column.
- get_meta_data() : array
- Get All Meta Data.
- get_object_read() : bool
- Get object read property.
- get_order_count() : int
- Return the number of orders this customer has.
- get_password() : string
- Get password (only used when updating the user object).
- get_postcode() : mixed
- Legacy get postcode.
- get_role() : string
- Return customer's user role.
- get_shipping() : array
- Get shipping.
- get_shipping_address() : string
- Get shipping_address_1.
- get_shipping_address_1() : string
- Get shipping_address_1.
- get_shipping_address_2() : string
- Get shipping_address_2.
- get_shipping_city() : string
- Get shipping_city.
- get_shipping_company() : string
- Get shipping_company.
- get_shipping_country() : string
- Get shipping_country.
- get_shipping_first_name() : string
- Get shipping_first_name.
- get_shipping_last_name() : string
- Get shipping_last_name.
- get_shipping_postcode() : string
- Get shipping_postcode.
- get_shipping_state() : string
- Get shipping_state.
- get_state() : mixed
- Legacy get state.
- get_taxable_address() : array
- Get taxable address.
- get_total_spent() : float
- Return how much money this customer has spent.
- get_username() : string
- Return the customer's username.
- has_calculated_shipping() : bool
- Has calculated shipping?
- is_customer_outside_base() : bool
- Is customer outside base country (for tax purposes)?
- is_paying_customer() : bool
- Is the user a paying customer?
- is_vat_exempt() : bool
- Is customer VAT exempt?
- meta_exists() : bool
- See if meta data exists, since get_meta always returns a '' or array().
- prime_raw_meta_data_cache() : mixed
- Prime caches for raw meta data. This includes meta_id column as well, which is not included by default in WP meta data.
- read_meta_data() : mixed
- Read Meta Data from the database. Ignore any internal properties.
- save() : int
- Save should create or update based on object existence.
- save_data() : mixed
- Save data function.
- save_meta_data() : mixed
- Update Meta Data in the database.
- set_address() : mixed
- Legacy set address.
- set_address_2() : mixed
- Legacy set address.
- set_billing_address() : mixed
- Set billing_address_1.
- set_billing_address_1() : mixed
- Set billing_address_1.
- set_billing_address_2() : mixed
- Set billing_address_2.
- set_billing_address_to_base() : mixed
- Set customer address to match shop base address.
- set_billing_city() : mixed
- Set billing_city.
- set_billing_company() : mixed
- Set billing_company.
- set_billing_country() : mixed
- Set billing_country.
- set_billing_email() : mixed
- Set billing_email.
- set_billing_first_name() : mixed
- Set billing_first_name.
- set_billing_last_name() : mixed
- Set billing_last_name.
- set_billing_location() : mixed
- Sets all address info at once.
- set_billing_phone() : mixed
- Set billing_phone.
- set_billing_postcode() : mixed
- Set billing_postcode.
- set_billing_state() : mixed
- Set billing_state.
- set_calculated_shipping() : mixed
- Calculated shipping?
- set_city() : mixed
- Legacy set city.
- set_country() : mixed
- Legacy set country.
- set_date_created() : mixed
- Set the date this customer was last updated.
- set_date_modified() : mixed
- Set the date this customer was last updated.
- set_default_data() : mixed
- Set default data for a customer.
- set_defaults() : mixed
- Set all props to default values.
- set_display_name() : mixed
- Set customer's display name.
- set_email() : mixed
- Set customer's email.
- set_first_name() : mixed
- Set customer's first name.
- set_id() : mixed
- Set ID.
- set_is_paying_customer() : mixed
- Set if the user a paying customer.
- set_is_vat_exempt() : mixed
- Set if customer has tax exemption.
- set_last_name() : mixed
- Set customer's last name.
- set_location() : mixed
- Sets session data for the location.
- set_meta_data() : mixed
- Set all meta data from array.
- set_object_read() : mixed
- Set object read property.
- set_password() : mixed
- Set customer's password.
- set_postcode() : mixed
- Legacy set postcode.
- set_props() : bool|WP_Error
- Set a collection of props in one go, collect any errors, and return the result.
- set_role() : mixed
- Set customer's user role(s).
- set_shipping_address() : mixed
- Set shipping_address_1.
- set_shipping_address_1() : mixed
- Set shipping_address_1.
- set_shipping_address_2() : mixed
- Set shipping_address_2.
- set_shipping_address_to_base() : mixed
- Set customer shipping address to base address.
- set_shipping_city() : mixed
- Set shipping_city.
- set_shipping_company() : mixed
- Set shipping_company.
- set_shipping_country() : mixed
- Set shipping_country.
- set_shipping_first_name() : mixed
- Set shipping_first_name.
- set_shipping_last_name() : mixed
- Set shipping_last_name.
- set_shipping_location() : mixed
- Sets all shipping info at once.
- set_shipping_postcode() : mixed
- Set shipping_postcode.
- set_shipping_state() : mixed
- Set shipping_state.
- set_shipping_to_base() : mixed
- Set customer shipping address to base address.
- set_state() : mixed
- Legacy set state.
- set_to_base() : mixed
- Set customer address to match shop base address.
- set_username() : mixed
- Set customer's username.
- update_meta_data() : mixed
- Update meta data by key or ID, if provided.
- error() : mixed
- When invalid data is found, throw an exception unless reading from the DB.
- filter_null_meta() : bool
- Filter null meta values from array.
- get_address_prop() : mixed
- Gets a prop for a getter method.
- get_hook_prefix() : string
- Prefix for action and filter hooks on data.
- get_prop() : mixed
- Gets a prop for a getter method.
- is_internal_meta_key() : bool
- Check if the key is an internal one.
- maybe_read_meta_data() : mixed
- Read meta data if null.
- set_address_prop() : mixed
- Sets a prop for a setter method.
- set_date_prop() : mixed
- Sets a date prop whilst handling formatting and datetime objects.
- set_prop() : mixed
- Sets a prop for a setter method.
- filter_legacy_key() : string
- Address and shipping_address are aliased, so we want to get the 'real' key name.
Properties
$cache_group
Stores meta in cache for future reads.
protected
string
$cache_group
= ''
A group must be set to to enable caching.
Tags
$calculated_shipping
Stores if user has calculated shipping in this session.
protected
string
$calculated_shipping
= alse
$changes
Core data changes for this object.
protected
array
$changes
= array()
Tags
$data
Stores customer data.
protected
array
$data
= array('date_created' =>
ull, 'date_modified' =>
ull, 'email' => '', 'first_name' => '', 'last_name' => '', 'display_name' => '', 'role' => 'customer', 'username' => '', 'billing' => array('first_name' => '', 'last_name' => '', 'company' => '', 'address_1' => '', 'address_2' => '', 'city' => '', 'postcode' => '', 'country' => '', 'state' => '', 'email' => '', 'phone' => ''), 'shipping' => array('first_name' => '', 'last_name' => '', 'company' => '', 'address_1' => '', 'address_2' => '', 'city' => '', 'postcode' => '', 'country' => '', 'state' => ''), 'is_paying_customer' => alse)
$data_store
Contains a reference to the data store for this class.
protected
object
$data_store
Tags
$default_data
Set to _data on construct so we can track and reset data if needed.
protected
array
$default_data
= array()
Tags
$extra_data
Extra data for this object. Name value pairs (name + default value).
protected
array
$extra_data
= array()
Used as a standard way for sub classes (like product types) to add additional information to an inherited class.
Tags
$id
ID for this object.
protected
int
$id
= 0
Tags
$is_vat_exempt
Stores if user is VAT exempt for this session.
protected
string
$is_vat_exempt
= alse
$meta_data
Stores additional meta data.
protected
array
$meta_data
=
ull
Tags
$object_read
This is false until the object is read from the DB.
protected
bool
$object_read
= alse
Tags
$object_type
This is the name of this object type.
protected
string
$object_type
= 'data'
Tags
$password
Stores a password if this needs to be changed. Write-only and hidden from _data.
protected
string
$password
= ''
Methods
__clone()
When the object is cloned, make sure meta is duplicated correctly.
public
__clone() : mixed
Tags
Return values
mixed__construct()
Load customer data based on how WC_Customer is called.
public
__construct(WC_Customer|int $data[, bool $is_session = false ]) : mixed
If $customer is 'new', you can build a new WC_Customer object. If it's empty, some data will be pulled from the session for the current user/customer.
Parameters
- $data : WC_Customer|int
-
Customer ID or data.
- $is_session : bool = false
-
True if this is the customer session.
Tags
Return values
mixed__get()
__get function.
public
__get(string $key) : string
Parameters
- $key : string
Return values
string__isset()
__isset legacy.
public
__isset(mixed $key) : bool
Parameters
- $key : mixed
Return values
bool__set()
__set function.
public
__set(string $key, mixed $value) : mixed
Parameters
- $key : string
- $value : mixed
Return values
mixed__sleep()
Only store the object ID to avoid serializing the data object instance.
public
__sleep() : array
Return values
array__toString()
Change data to JSON format.
public
__toString() : string
Tags
Return values
string — Data in JSON format.__wakeup()
Re-run the constructor with the object ID.
public
__wakeup() : mixed
If the object no longer exists, remove the ID.
Return values
mixedadd_meta_data()
Add meta data.
public
add_meta_data(string $key, string|array $value[, bool $unique = false ]) : mixed
Parameters
- $key : string
-
Meta key.
- $value : string|array
-
Meta value.
- $unique : bool = false
-
Should this be a unique key?.
Tags
Return values
mixedapply_changes()
Merge changes with data and clear.
public
apply_changes() : mixed
Tags
Return values
mixedcalculated_shipping()
Calculated shipping.
public
calculated_shipping([bool $calculated = true ]) : mixed
Parameters
- $calculated : bool = true
Return values
mixeddelete()
Delete an object, set the ID to 0, and return result.
public
delete([bool $force_delete = false ]) : bool
Parameters
- $force_delete : bool = false
-
Should the date be deleted permanently.
Tags
Return values
bool — resultdelete_and_reassign()
Delete a customer and reassign posts.
public
delete_and_reassign([int $reassign = null ]) : bool
.
Parameters
- $reassign : int = null
-
Reassign posts and links to new User ID.
Tags
Return values
booldelete_meta_data()
Delete meta data.
public
delete_meta_data(string $key) : mixed
Parameters
- $key : string
-
Meta key.
Tags
Return values
mixeddelete_meta_data_by_mid()
Delete meta data.
public
delete_meta_data_by_mid(int $mid) : mixed
Parameters
- $mid : int
-
Meta ID.
Tags
Return values
mixedgenerate_meta_cache_key()
Generate cache key from id and group.
public
static generate_meta_cache_key(int|string $id, string $cache_group) : string
Parameters
- $id : int|string
-
Object ID.
- $cache_group : string
-
Group name use to store cache. Whole group cache can be invalidated in one go.
Tags
Return values
string — Meta cache key.get_address()
Legacy get address.
public
get_address() : mixed
Return values
mixedget_address_2()
Legacy get address 2.
public
get_address_2() : mixed
Return values
mixedget_avatar_url()
Return this customer's avatar.
public
get_avatar_url() : string
Tags
Return values
stringget_billing()
Get billing.
public
get_billing([string $context = 'view' ]) : array
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
arrayget_billing_address()
Get billing_address_1.
public
get_billing_address([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_billing_address_1()
Get billing_address_1.
public
get_billing_address_1([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_billing_address_2()
Get billing_address_2.
public
get_billing_address_2([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
string — $valueget_billing_city()
Get billing_city.
public
get_billing_city([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
string — $valueget_billing_company()
Get billing_company.
public
get_billing_company([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_billing_country()
Get billing_country.
public
get_billing_country([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_billing_email()
Get billing_email.
public
get_billing_email([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_billing_first_name()
Get billing_first_name.
public
get_billing_first_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_billing_last_name()
Get billing_last_name.
public
get_billing_last_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_billing_phone()
Get billing_phone.
public
get_billing_phone([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_billing_postcode()
Get billing_postcode.
public
get_billing_postcode([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_billing_state()
Get billing_state.
public
get_billing_state([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_calculated_shipping()
Has customer calculated shipping?
public
get_calculated_shipping() : bool
Return values
boolget_changes()
Return data changes only.
public
get_changes() : array
Tags
Return values
arrayget_city()
Legacy get city.
public
get_city() : mixed
Return values
mixedget_country()
Legacy get country.
public
get_country() : mixed
Return values
mixedget_data()
Returns all data for this object.
public
get_data() : array
Tags
Return values
arrayget_data_keys()
Returns array of expected data keys for this object.
public
get_data_keys() : array
Tags
Return values
arrayget_data_store()
Get the data store.
public
get_data_store() : object
Tags
Return values
objectget_date_created()
Return the date this customer was created.
public
get_date_created([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_date_modified()
Return the date this customer was last updated.
public
get_date_modified([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_default_country()
Get default country for a customer.
public
get_default_country() : string
Return values
stringget_default_state()
Get default state for a customer.
public
get_default_state() : string
Return values
stringget_display_name()
Return customer's display name.
public
get_display_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
stringget_downloadable_products()
Gets a customer's downloadable products.
public
get_downloadable_products() : array
Return values
array — Array of downloadable productsget_email()
Return the customer's email.
public
get_email([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
stringget_extra_data_keys()
Returns all "extra" data keys for an object (for sub objects like product types).
public
get_extra_data_keys() : array
Tags
Return values
arrayget_first_name()
Return customer's first name.
public
get_first_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
stringget_id()
Returns the unique ID for this object.
public
get_id() : int
Tags
Return values
intget_is_paying_customer()
Is the user a paying customer?
public
get_is_paying_customer([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
boolget_is_vat_exempt()
Get if customer is VAT exempt?
public
get_is_vat_exempt() : bool
Tags
Return values
boolget_last_name()
Return customer's last name.
public
get_last_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
stringget_last_order()
Gets the customers last order.
public
get_last_order() : WC_Order|false
Return values
WC_Order|falseget_meta()
Get Meta Data by Key.
public
get_meta([string $key = '' ][, bool $single = true ][, string $context = 'view' ]) : mixed
Parameters
- $key : string = ''
-
Meta Key.
- $single : bool = true
-
return first found meta with key, or all with $key.
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
mixedget_meta_cache_key()
Helper method to compute meta cache key. Different from WP Meta cache key in that meta data cached using this key also contains meta_id column.
public
get_meta_cache_key() : string
Tags
Return values
stringget_meta_data()
Get All Meta Data.
public
get_meta_data() : array
Tags
Return values
array — of objects.get_object_read()
Get object read property.
public
get_object_read() : bool
Tags
Return values
boolget_order_count()
Return the number of orders this customer has.
public
get_order_count() : int
Return values
intget_password()
Get password (only used when updating the user object).
public
get_password() : string
Return values
stringget_postcode()
Legacy get postcode.
public
get_postcode() : mixed
Return values
mixedget_role()
Return customer's user role.
public
get_role([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
stringget_shipping()
Get shipping.
public
get_shipping([string $context = 'view' ]) : array
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
arrayget_shipping_address()
Get shipping_address_1.
public
get_shipping_address([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_shipping_address_1()
Get shipping_address_1.
public
get_shipping_address_1([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_shipping_address_2()
Get shipping_address_2.
public
get_shipping_address_2([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_shipping_city()
Get shipping_city.
public
get_shipping_city([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_shipping_company()
Get shipping_company.
public
get_shipping_company([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_shipping_country()
Get shipping_country.
public
get_shipping_country([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_shipping_first_name()
Get shipping_first_name.
public
get_shipping_first_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_shipping_last_name()
Get shipping_last_name.
public
get_shipping_last_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_shipping_postcode()
Get shipping_postcode.
public
get_shipping_postcode([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_shipping_state()
Get shipping_state.
public
get_shipping_state([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
stringget_state()
Legacy get state.
public
get_state() : mixed
Return values
mixedget_taxable_address()
Get taxable address.
public
get_taxable_address() : array
Return values
arrayget_total_spent()
Return how much money this customer has spent.
public
get_total_spent() : float
Return values
floatget_username()
Return the customer's username.
public
get_username([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Tags
Return values
stringhas_calculated_shipping()
Has calculated shipping?
public
has_calculated_shipping() : bool
Return values
boolis_customer_outside_base()
Is customer outside base country (for tax purposes)?
public
is_customer_outside_base() : bool
Return values
boolis_paying_customer()
Is the user a paying customer?
public
is_paying_customer([int $user_id = '' ]) : bool
Parameters
- $user_id : int = ''
Return values
boolis_vat_exempt()
Is customer VAT exempt?
public
is_vat_exempt() : bool
Return values
boolmeta_exists()
See if meta data exists, since get_meta always returns a '' or array().
public
meta_exists([string $key = '' ]) : bool
Parameters
- $key : string = ''
-
Meta Key.
Tags
Return values
boolprime_raw_meta_data_cache()
Prime caches for raw meta data. This includes meta_id column as well, which is not included by default in WP meta data.
public
static prime_raw_meta_data_cache(array $raw_meta_data_collection, string $cache_group) : mixed
Parameters
- $raw_meta_data_collection : array
-
Array of objects of { object_id => array( meta_row_1, meta_row_2, ... }.
- $cache_group : string
-
Name of cache group.
Tags
Return values
mixedread_meta_data()
Read Meta Data from the database. Ignore any internal properties.
public
read_meta_data([bool $force_read = false ]) : mixed
Uses it's own caches because get_metadata does not provide meta_ids.
Parameters
- $force_read : bool = false
-
True to force a new DB read (and update cache).
Tags
Return values
mixedsave()
Save should create or update based on object existence.
public
save() : int
Tags
Return values
intsave_data()
Save data function.
public
save_data() : mixed
Return values
mixedsave_meta_data()
Update Meta Data in the database.
public
save_meta_data() : mixed
Tags
Return values
mixedset_address()
Legacy set address.
public
set_address(string $address) : mixed
Parameters
- $address : string
Return values
mixedset_address_2()
Legacy set address.
public
set_address_2(string $address) : mixed
Parameters
- $address : string
Return values
mixedset_billing_address()
Set billing_address_1.
public
set_billing_address(string $value) : mixed
Parameters
- $value : string
-
Billing address line 1.
Return values
mixedset_billing_address_1()
Set billing_address_1.
public
set_billing_address_1(string $value) : mixed
Parameters
- $value : string
-
Billing address line 1.
Return values
mixedset_billing_address_2()
Set billing_address_2.
public
set_billing_address_2(string $value) : mixed
Parameters
- $value : string
-
Billing address line 2.
Return values
mixedset_billing_address_to_base()
Set customer address to match shop base address.
public
set_billing_address_to_base() : mixed
Tags
Return values
mixedset_billing_city()
Set billing_city.
public
set_billing_city(string $value) : mixed
Parameters
- $value : string
-
Billing city.
Return values
mixedset_billing_company()
Set billing_company.
public
set_billing_company(string $value) : mixed
Parameters
- $value : string
-
Billing company.
Return values
mixedset_billing_country()
Set billing_country.
public
set_billing_country(string $value) : mixed
Parameters
- $value : string
-
Billing country.
Return values
mixedset_billing_email()
Set billing_email.
public
set_billing_email(string $value) : mixed
Parameters
- $value : string
-
Billing email.
Return values
mixedset_billing_first_name()
Set billing_first_name.
public
set_billing_first_name(string $value) : mixed
Parameters
- $value : string
-
Billing first name.
Return values
mixedset_billing_last_name()
Set billing_last_name.
public
set_billing_last_name(string $value) : mixed
Parameters
- $value : string
-
Billing last name.
Return values
mixedset_billing_location()
Sets all address info at once.
public
set_billing_location(string $country[, string $state = '' ][, string $postcode = '' ][, string $city = '' ]) : mixed
Parameters
- $country : string
-
Country.
- $state : string = ''
-
State.
- $postcode : string = ''
-
Postcode.
- $city : string = ''
-
City.
Return values
mixedset_billing_phone()
Set billing_phone.
public
set_billing_phone(string $value) : mixed
Parameters
- $value : string
-
Billing phone.
Return values
mixedset_billing_postcode()
Set billing_postcode.
public
set_billing_postcode(string $value) : mixed
Parameters
- $value : string
-
Billing postcode.
Return values
mixedset_billing_state()
Set billing_state.
public
set_billing_state(string $value) : mixed
Parameters
- $value : string
-
Billing state.
Return values
mixedset_calculated_shipping()
Calculated shipping?
public
set_calculated_shipping([bool $calculated = true ]) : mixed
Parameters
- $calculated : bool = true
-
If shipping is calculated.
Return values
mixedset_city()
Legacy set city.
public
set_city(string $city) : mixed
Parameters
- $city : string
Return values
mixedset_country()
Legacy set country.
public
set_country(string $country) : mixed
Parameters
- $country : string
Return values
mixedset_date_created()
Set the date this customer was last updated.
public
set_date_created([string|int|null $date = null ]) : mixed
Parameters
- $date : string|int|null = null
-
UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
Tags
Return values
mixedset_date_modified()
Set the date this customer was last updated.
public
set_date_modified([string|int|null $date = null ]) : mixed
Parameters
- $date : string|int|null = null
-
UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
Tags
Return values
mixedset_default_data()
Set default data for a customer.
public
set_default_data() : mixed
Return values
mixedset_defaults()
Set all props to default values.
public
set_defaults() : mixed
Tags
Return values
mixedset_display_name()
Set customer's display name.
public
set_display_name(string $display_name) : mixed
Parameters
- $display_name : string
-
Display name.
Tags
Return values
mixedset_email()
Set customer's email.
public
set_email(string $value) : mixed
Parameters
- $value : string
-
Email.
Tags
Return values
mixedset_first_name()
Set customer's first name.
public
set_first_name(string $first_name) : mixed
Parameters
- $first_name : string
-
First name.
Tags
Return values
mixedset_id()
Set ID.
public
set_id(int $id) : mixed
Parameters
- $id : int
-
ID.
Tags
Return values
mixedset_is_paying_customer()
Set if the user a paying customer.
public
set_is_paying_customer(bool $is_paying_customer) : mixed
Parameters
- $is_paying_customer : bool
-
If is a paying customer.
Tags
Return values
mixedset_is_vat_exempt()
Set if customer has tax exemption.
public
set_is_vat_exempt(bool $is_vat_exempt) : mixed
Parameters
- $is_vat_exempt : bool
-
If is vat exempt.
Return values
mixedset_last_name()
Set customer's last name.
public
set_last_name(string $last_name) : mixed
Parameters
- $last_name : string
-
Last name.
Tags
Return values
mixedset_location()
Sets session data for the location.
public
set_location(string $country, string $state[, string $postcode = '' ][, string $city = '' ]) : mixed
Parameters
- $country : string
- $state : string
- $postcode : string = ''
-
(default: '')
- $city : string = ''
-
(default: '')
Return values
mixedset_meta_data()
Set all meta data from array.
public
set_meta_data(array $data) : mixed
Parameters
- $data : array
-
Key/Value pairs.
Tags
Return values
mixedset_object_read()
Set object read property.
public
set_object_read([bool $read = true ]) : mixed
Parameters
- $read : bool = true
-
Should read?.
Tags
Return values
mixedset_password()
Set customer's password.
public
set_password(string $password) : mixed
Parameters
- $password : string
-
Password.
Tags
Return values
mixedset_postcode()
Legacy set postcode.
public
set_postcode(string $postcode) : mixed
Parameters
- $postcode : string
Return values
mixedset_props()
Set a collection of props in one go, collect any errors, and return the result.
public
set_props(array $props[, string $context = 'set' ]) : bool|WP_Error
Only sets using public methods.
Parameters
- $props : array
-
Key value pairs to set. Key is the prop and should map to a setter function name.
- $context : string = 'set'
-
In what context to run this.
Tags
Return values
bool|WP_Errorset_role()
Set customer's user role(s).
public
set_role(mixed $role) : mixed
Parameters
- $role : mixed
-
User role.
Tags
Return values
mixedset_shipping_address()
Set shipping_address_1.
public
set_shipping_address(string $value) : mixed
Parameters
- $value : string
-
Shipping address line 1.
Return values
mixedset_shipping_address_1()
Set shipping_address_1.
public
set_shipping_address_1(string $value) : mixed
Parameters
- $value : string
-
Shipping address line 1.
Return values
mixedset_shipping_address_2()
Set shipping_address_2.
public
set_shipping_address_2(string $value) : mixed
Parameters
- $value : string
-
Shipping address line 2.
Return values
mixedset_shipping_address_to_base()
Set customer shipping address to base address.
public
set_shipping_address_to_base() : mixed
Tags
Return values
mixedset_shipping_city()
Set shipping_city.
public
set_shipping_city(string $value) : mixed
Parameters
- $value : string
-
Shipping city.
Return values
mixedset_shipping_company()
Set shipping_company.
public
set_shipping_company(string $value) : mixed
Parameters
- $value : string
-
Shipping company.
Return values
mixedset_shipping_country()
Set shipping_country.
public
set_shipping_country(string $value) : mixed
Parameters
- $value : string
-
Shipping country.
Return values
mixedset_shipping_first_name()
Set shipping_first_name.
public
set_shipping_first_name(string $value) : mixed
Parameters
- $value : string
-
Shipping first name.
Return values
mixedset_shipping_last_name()
Set shipping_last_name.
public
set_shipping_last_name(string $value) : mixed
Parameters
- $value : string
-
Shipping last name.
Return values
mixedset_shipping_location()
Sets all shipping info at once.
public
set_shipping_location(string $country[, string $state = '' ][, string $postcode = '' ][, string $city = '' ]) : mixed
Parameters
- $country : string
-
Country.
- $state : string = ''
-
State.
- $postcode : string = ''
-
Postcode.
- $city : string = ''
-
City.
Return values
mixedset_shipping_postcode()
Set shipping_postcode.
public
set_shipping_postcode(string $value) : mixed
Parameters
- $value : string
-
Shipping postcode.
Return values
mixedset_shipping_state()
Set shipping_state.
public
set_shipping_state(string $value) : mixed
Parameters
- $value : string
-
Shipping state.
Return values
mixedset_shipping_to_base()
Set customer shipping address to base address.
public
set_shipping_to_base() : mixed
Return values
mixedset_state()
Legacy set state.
public
set_state(string $state) : mixed
Parameters
- $state : string
Return values
mixedset_to_base()
Set customer address to match shop base address.
public
set_to_base() : mixed
Return values
mixedset_username()
Set customer's username.
public
set_username(string $username) : mixed
Parameters
- $username : string
-
Username.
Tags
Return values
mixedupdate_meta_data()
Update meta data by key or ID, if provided.
public
update_meta_data(string $key, string|array $value, int $meta_id) : mixed
Parameters
- $key : string
-
Meta key.
- $value : string|array
-
Meta value.
- $meta_id : int
-
Meta ID.
Tags
Return values
mixederror()
When invalid data is found, throw an exception unless reading from the DB.
protected
error(string $code, string $message[, int $http_status_code = 400 ][, array $data = array() ]) : mixed
Parameters
- $code : string
-
Error code.
- $message : string
-
Error message.
- $http_status_code : int = 400
-
HTTP status code.
- $data : array = array()
-
Extra error data.
Tags
Return values
mixedfilter_null_meta()
Filter null meta values from array.
protected
filter_null_meta(mixed $meta) : bool
Parameters
- $meta : mixed
-
Meta value to check.
Tags
Return values
boolget_address_prop()
Gets a prop for a getter method.
protected
get_address_prop(string $prop[, string $address = 'billing' ][, string $context = 'view' ]) : mixed
Parameters
- $prop : string
-
Name of prop to get.
- $address : string = 'billing'
-
billing or shipping.
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'. What the value is for. Valid values are view and edit.
Tags
Return values
mixedget_hook_prefix()
Prefix for action and filter hooks on data.
protected
get_hook_prefix() : string
Tags
Return values
stringget_prop()
Gets a prop for a getter method.
protected
get_prop(string $prop[, string $context = 'view' ]) : mixed
Gets the value from either current pending changes, or the data itself. Context controls what happens to the value before it's returned.
Parameters
- $prop : string
-
Name of prop to get.
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
mixedis_internal_meta_key()
Check if the key is an internal one.
protected
is_internal_meta_key(string $key) : bool
Parameters
- $key : string
-
Key to check.
Tags
Return values
bool — true if it's an internal key, false otherwisemaybe_read_meta_data()
Read meta data if null.
protected
maybe_read_meta_data() : mixed
Tags
Return values
mixedset_address_prop()
Sets a prop for a setter method.
protected
set_address_prop(string $prop, string $address, mixed $value) : mixed
Parameters
- $prop : string
-
Name of prop to set.
- $address : string
-
Name of address to set. billing or shipping.
- $value : mixed
-
Value of the prop.
Tags
Return values
mixedset_date_prop()
Sets a date prop whilst handling formatting and datetime objects.
protected
set_date_prop(string $prop, string|int $value) : mixed
Parameters
- $prop : string
-
Name of prop to set.
- $value : string|int
-
Value of the prop.
Tags
Return values
mixedset_prop()
Sets a prop for a setter method.
protected
set_prop(string $prop, mixed $value) : mixed
This stores changes in a special array so we can track what needs saving the the DB later.
Parameters
- $prop : string
-
Name of prop to set.
- $value : mixed
-
Value of the prop.
Tags
Return values
mixedfilter_legacy_key()
Address and shipping_address are aliased, so we want to get the 'real' key name.
private
filter_legacy_key(string $key) : string
For all other keys, we can just return it.
Parameters
- $key : string