WooCommerce Code Reference

WC_Customer extends WC_Legacy_Customer
in package

Customer class.

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<string|int, mixed>
Core data changes for this object.
$data  : array<string|int, mixed>
Stores customer data.
$data_store  : object
Contains a reference to the data store for this class.
$default_data  : array<string|int, mixed>
Set to _data on construct so we can track and reset data if needed.
$extra_data  : array<string|int, mixed>
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.
$legacy_datastore_props  : array<string|int, mixed>
List of properties that were earlier managed by data store. However, since DataStore is a not a stored entity in itself, they used to store data in metadata of the data object.
$meta_data  : array<string|int, mixed>
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<string|int, mixed>
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.
delete_meta_data_value()  : mixed
Delete meta data with a matching value.
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<string|int, mixed>
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<string|int, mixed>
Return data changes only.
get_city()  : mixed
Legacy get city.
get_country()  : mixed
Legacy get country.
get_data()  : array<string|int, mixed>
Returns all data for this object.
get_data_keys()  : array<string|int, mixed>
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<string|int, mixed>
Gets a customer's downloadable products.
get_email()  : string
Return the customer's email.
get_extra_data_keys()  : array<string|int, mixed>
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<string|int, mixed>
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<string|int, mixed>
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_phone()  : string
Get shipping phone.
get_shipping_postcode()  : string
Get shipping_postcode.
get_shipping_state()  : string
Get shipping_state.
get_state()  : mixed
Legacy get state.
get_taxable_address()  : array<string|int, mixed>
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?
has_shipping_address()  : bool
Indicates if the customer has a non-empty shipping address.
init_meta_data()  : mixed
Helper function to initialize metadata entries from filtered raw meta data.
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_phone()  : mixed
Set shipping phone.
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

$calculated_shipping

Stores if user has calculated shipping in this session.

protected string $calculated_shipping = alse

$data

Stores customer data.

protected array<string|int, mixed> $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' => '', 'phone' => ''), 'is_paying_customer' => alse)

$default_data

Set to _data on construct so we can track and reset data if needed.

protected array<string|int, mixed> $default_data = array()
Tags
since
3.0.0

$extra_data

Extra data for this object. Name value pairs (name + default value).

protected array<string|int, mixed> $extra_data = array()

Used as a standard way for sub classes (like product types) to add additional information to an inherited class.

Tags
since
3.0.0

$legacy_datastore_props

List of properties that were earlier managed by data store. However, since DataStore is a not a stored entity in itself, they used to store data in metadata of the data object.

protected array<string|int, mixed> $legacy_datastore_props = array()

With custom tables, some of these are moved from metadata to their own columns, but existing code will still try to add them to metadata. This array is used to keep track of such properties.

Only reason to add a property here is that you are moving properties from DataStore instance to data object. If you are adding a new property, consider adding it to to $data array instead.

$password

Stores a password if this needs to be changed. Write-only and hidden from _data.

protected string $password = ''

Methods

__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
throws
Exception

If customer cannot be read/found and $data is set.

Return values
mixed

__sleep()

Only store the object ID to avoid serializing the data object instance.

public __sleep() : array<string|int, mixed>
Return values
array<string|int, mixed>

__wakeup()

Re-run the constructor with the object ID.

public __wakeup() : mixed

If the object no longer exists, remove the ID.

Return values
mixed

add_meta_data()

Add meta data.

public add_meta_data(string $key, string|array<string|int, mixed> $value[, bool $unique = false ]) : mixed
Parameters
$key : string

Meta key.

$value : string|array<string|int, mixed>

Meta value.

$unique : bool = false

Should this be a unique key?.

Tags
since
2.6.0
Return values
mixed

calculated_shipping()

Calculated shipping.

public calculated_shipping([bool $calculated = true ]) : mixed
Parameters
$calculated : bool = true
Return values
mixed

delete()

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
since
2.6.0
Return values
boolresult

delete_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
since
3.0.0
Return values
bool

delete_meta_data()

Delete meta data.

public delete_meta_data(string $key) : mixed
Parameters
$key : string

Meta key.

Tags
since
2.6.0
Return values
mixed

delete_meta_data_by_mid()

Delete meta data.

public delete_meta_data_by_mid(int $mid) : mixed
Parameters
$mid : int

Meta ID.

Tags
since
2.6.0
Return values
mixed

delete_meta_data_value()

Delete meta data with a matching value.

public delete_meta_data_value(string $key, mixed $value) : mixed
Parameters
$key : string

Meta key.

$value : mixed

Meta value. Entries will only be removed that match the value.

Tags
since
7.7.0
Return values
mixed

generate_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
since
4.7.0
Return values
stringMeta cache key.

get_avatar_url()

Return this customer's avatar.

public get_avatar_url() : string
Tags
since
3.0.0
Return values
string

get_billing()

Get billing.

public get_billing([string $context = 'view' ]) : array<string|int, mixed>
Parameters
$context : string = 'view'

What the value is for. Valid values are 'view' and 'edit'.

Tags
since
3.2.0
Return values
array<string|int, mixed>

get_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
string

get_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
string

get_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$value

get_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$value

get_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
string

get_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
string

get_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
string

get_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
string

get_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
string

get_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
string

get_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
string

get_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
string

get_calculated_shipping()

Has customer calculated shipping?

public get_calculated_shipping() : bool
Return values
bool

get_changes()

Return data changes only.

public get_changes() : array<string|int, mixed>
Tags
since
3.0.0
Return values
array<string|int, mixed>

get_data()

Returns all data for this object.

public get_data() : array<string|int, mixed>
Tags
since
2.6.0
Return values
array<string|int, mixed>

get_data_keys()

Returns array of expected data keys for this object.

public get_data_keys() : array<string|int, mixed>
Tags
since
3.0.0
Return values
array<string|int, mixed>

get_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
since
3.0.0
Return values
WC_DateTime|nullobject 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
since
3.0.0
Return values
WC_DateTime|nullobject if the date is set or null if there is no date.

get_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
since
3.1.0
Return values
string

get_downloadable_products()

Gets a customer's downloadable products.

public get_downloadable_products() : array<string|int, mixed>
Return values
array<string|int, mixed>Array of downloadable products

get_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
since
3.0.0
Return values
string

get_extra_data_keys()

Returns all "extra" data keys for an object (for sub objects like product types).

public get_extra_data_keys() : array<string|int, mixed>
Tags
since
3.0.0
Return values
array<string|int, mixed>

get_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
since
3.0.0
Return values
string

get_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
since
3.0.0
Return values
bool

get_is_vat_exempt()

Get if customer is VAT exempt?

public get_is_vat_exempt() : bool
Tags
since
3.0.0
Return values
bool

get_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
since
3.0.0
Return values
string

get_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
since
2.6.0
Return values
mixed

get_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
since
4.7.0
Return values
string

get_meta_data()

Get All Meta Data.

public get_meta_data() : array<string|int, mixed>
Tags
since
2.6.0
Return values
array<string|int, mixed>of objects.

get_order_count()

Return the number of orders this customer has.

public get_order_count() : int
Return values
int

get_password()

Get password (only used when updating the user object).

public get_password() : string
Return values
string

get_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
since
3.0.0
Return values
string

get_shipping()

Get shipping.

public get_shipping([string $context = 'view' ]) : array<string|int, mixed>
Parameters
$context : string = 'view'

What the value is for. Valid values are 'view' and 'edit'.

Tags
since
3.2.0
Return values
array<string|int, mixed>

get_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
string

get_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
string

get_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
string

get_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
string

get_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
string

get_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
string

get_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
string

get_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
string

get_shipping_phone()

Get shipping phone.

public get_shipping_phone([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are 'view' and 'edit'.

Tags
since
5.6.0
Return values
string

get_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
string

get_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
string

get_taxable_address()

Get taxable address.

public get_taxable_address() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_total_spent()

Return how much money this customer has spent.

public get_total_spent() : float
Return values
float

get_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
since
3.0.0
Return values
string

has_calculated_shipping()

Has calculated shipping?

public has_calculated_shipping() : bool
Return values
bool

has_shipping_address()

Indicates if the customer has a non-empty shipping address.

public has_shipping_address() : bool

Note that this does not indicate if the customer's shipping address is complete, only that one or more fields are populated.

Tags
since
5.3.0
Return values
bool

init_meta_data()

Helper function to initialize metadata entries from filtered raw meta data.

public init_meta_data([array<string|int, mixed> $filtered_meta_data = array() ]) : mixed
Parameters
$filtered_meta_data : array<string|int, mixed> = array()

Filtered metadata fetched from DB.

Return values
mixed

is_customer_outside_base()

Is customer outside base country (for tax purposes)?

public is_customer_outside_base() : bool
Return values
bool

meta_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
since
3.0.0
Return values
bool

prime_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<string|int, mixed> $raw_meta_data_collection, string $cache_group) : mixed
Parameters
$raw_meta_data_collection : array<string|int, mixed>

Array of objects of { object_id => array( meta_row_1, meta_row_2, ... }.

$cache_group : string

Name of cache group.

Tags
since
4.7.0
Return values
mixed

read_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
since
2.6.0
Return values
mixed

set_billing_address()

Set billing_address_1.

public set_billing_address(string $value) : mixed
Parameters
$value : string

Billing address line 1.

Return values
mixed

set_billing_address_1()

Set billing_address_1.

public set_billing_address_1(string $value) : mixed
Parameters
$value : string

Billing address line 1.

Return values
mixed

set_billing_address_2()

Set billing_address_2.

public set_billing_address_2(string $value) : mixed
Parameters
$value : string

Billing address line 2.

Return values
mixed

set_billing_address_to_base()

Set customer address to match shop base address.

public set_billing_address_to_base() : mixed
Tags
since
3.0.0
Return values
mixed

set_billing_city()

Set billing_city.

public set_billing_city(string $value) : mixed
Parameters
$value : string

Billing city.

Return values
mixed

set_billing_company()

Set billing_company.

public set_billing_company(string $value) : mixed
Parameters
$value : string

Billing company.

Return values
mixed

set_billing_country()

Set billing_country.

public set_billing_country(string $value) : mixed
Parameters
$value : string

Billing country.

Return values
mixed

set_billing_email()

Set billing_email.

public set_billing_email(string $value) : mixed
Parameters
$value : string

Billing email.

Return values
mixed

set_billing_first_name()

Set billing_first_name.

public set_billing_first_name(string $value) : mixed
Parameters
$value : string

Billing first name.

Return values
mixed

set_billing_last_name()

Set billing_last_name.

public set_billing_last_name(string $value) : mixed
Parameters
$value : string

Billing last name.

Return values
mixed

set_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
mixed

set_billing_phone()

Set billing_phone.

public set_billing_phone(string $value) : mixed
Parameters
$value : string

Billing phone.

Return values
mixed

set_billing_postcode()

Set billing_postcode.

public set_billing_postcode(string $value) : mixed
Parameters
$value : string

Billing postcode.

Return values
mixed

set_billing_state()

Set billing_state.

public set_billing_state(string $value) : mixed
Parameters
$value : string

Billing state.

Return values
mixed

set_calculated_shipping()

Calculated shipping?

public set_calculated_shipping([bool $calculated = true ]) : mixed
Parameters
$calculated : bool = true

If shipping is calculated.

Return values
mixed

set_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
since
3.0.0
Return values
mixed

set_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
since
3.0.0
Return values
mixed

set_display_name()

Set customer's display name.

public set_display_name(string $display_name) : mixed
Parameters
$display_name : string

Display name.

Tags
since
3.1.0
Return values
mixed

set_email()

Set customer's email.

public set_email(string $value) : mixed
Parameters
$value : string

Email.

Tags
since
3.0.0
Return values
mixed

set_first_name()

Set customer's first name.

public set_first_name(string $first_name) : mixed
Parameters
$first_name : string

First name.

Tags
since
3.0.0
Return values
mixed

set_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
since
3.0.0
Return values
mixed

set_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
mixed

set_last_name()

Set customer's last name.

public set_last_name(string $last_name) : mixed
Parameters
$last_name : string

Last name.

Tags
since
3.0.0
Return values
mixed

set_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
mixed

set_meta_data()

Set all meta data from array.

public set_meta_data(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>

Key/Value pairs.

Tags
since
2.6.0
Return values
mixed

set_object_read()

Set object read property.

public set_object_read([bool $read = true ]) : mixed
Parameters
$read : bool = true

Should read?.

Tags
since
3.0.0
Return values
mixed

set_password()

Set customer's password.

public set_password(string $password) : mixed
Parameters
$password : string

Password.

Tags
since
3.0.0
Return values
mixed

set_props()

Set a collection of props in one go, collect any errors, and return the result.

public set_props(array<string|int, mixed> $props[, string $context = 'set' ]) : bool|WP_Error

Only sets using public methods.

Parameters
$props : array<string|int, mixed>

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
since
3.0.0
Return values
bool|WP_Error

set_role()

Set customer's user role(s).

public set_role(mixed $role) : mixed
Parameters
$role : mixed

User role.

Tags
since
3.0.0
Return values
mixed

set_shipping_address()

Set shipping_address_1.

public set_shipping_address(string $value) : mixed
Parameters
$value : string

Shipping address line 1.

Return values
mixed

set_shipping_address_1()

Set shipping_address_1.

public set_shipping_address_1(string $value) : mixed
Parameters
$value : string

Shipping address line 1.

Return values
mixed

set_shipping_address_2()

Set shipping_address_2.

public set_shipping_address_2(string $value) : mixed
Parameters
$value : string

Shipping address line 2.

Return values
mixed

set_shipping_address_to_base()

Set customer shipping address to base address.

public set_shipping_address_to_base() : mixed
Tags
since
3.0.0
Return values
mixed

set_shipping_city()

Set shipping_city.

public set_shipping_city(string $value) : mixed
Parameters
$value : string

Shipping city.

Return values
mixed

set_shipping_company()

Set shipping_company.

public set_shipping_company(string $value) : mixed
Parameters
$value : string

Shipping company.

Return values
mixed

set_shipping_country()

Set shipping_country.

public set_shipping_country(string $value) : mixed
Parameters
$value : string

Shipping country.

Return values
mixed

set_shipping_first_name()

Set shipping_first_name.

public set_shipping_first_name(string $value) : mixed
Parameters
$value : string

Shipping first name.

Return values
mixed

set_shipping_last_name()

Set shipping_last_name.

public set_shipping_last_name(string $value) : mixed
Parameters
$value : string

Shipping last name.

Return values
mixed

set_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
mixed

set_shipping_phone()

Set shipping phone.

public set_shipping_phone(string $value) : mixed
Parameters
$value : string

Shipping phone.

Tags
since
5.6.0
Return values
mixed

set_shipping_postcode()

Set shipping_postcode.

public set_shipping_postcode(string $value) : mixed
Parameters
$value : string

Shipping postcode.

Return values
mixed

set_shipping_state()

Set shipping_state.

public set_shipping_state(string $value) : mixed
Parameters
$value : string

Shipping state.

Return values
mixed

set_username()

Set customer's username.

public set_username(string $username) : mixed
Parameters
$username : string

Username.

Tags
since
3.0.0
Return values
mixed

update_meta_data()

Update meta data by key or ID, if provided.

public update_meta_data(string $key, string|array<string|int, mixed> $value, int $meta_id) : mixed
Parameters
$key : string

Meta key.

$value : string|array<string|int, mixed>

Meta value.

$meta_id : int

Meta ID.

Tags
since
2.6.0
Return values
mixed

error()

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<string|int, mixed> $data = array() ]) : mixed
Parameters
$code : string

Error code.

$message : string

Error message.

$http_status_code : int = 400

HTTP status code.

$data : array<string|int, mixed> = array()

Extra error data.

Tags
throws
WC_Data_Exception

Data Exception.

since
3.0.0
Return values
mixed

filter_null_meta()

Filter null meta values from array.

protected filter_null_meta(mixed $meta) : bool
Parameters
$meta : mixed

Meta value to check.

Tags
since
3.0.0
Return values
bool

get_address_prop()

Gets a prop for a getter method.

protected get_address_prop(string $prop[, string $address_type = 'billing' ][, string $context = 'view' ]) : mixed
Parameters
$prop : string

Name of prop to get.

$address_type : string = 'billing'

Type of address; 'billing' or 'shipping'.

$context : string = 'view'

What the value is for. Valid values are 'view' and 'edit'.

Tags
since
3.0.0
Return values
mixed

get_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
since
3.0.0
Return values
mixed

is_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
since
3.2.0
Return values
booltrue if it's an internal key, false otherwise

set_address_prop()

Sets a prop for a setter method.

protected set_address_prop(string $prop, string $address_type, mixed $value) : mixed
Parameters
$prop : string

Name of prop to set.

$address_type : string

Type of address; 'billing' or 'shipping'.

$value : mixed

Value of the prop.

Tags
since
3.0.0
Return values
mixed

set_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
since
3.0.0
Return values
mixed

set_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 DB later.

Parameters
$prop : string

Name of prop to set.

$value : mixed

Value of the prop.

Tags
since
3.0.0
Return values
mixed

filter_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
Tags
since
3.0.0
Return values
string