WooCommerce Code Reference

WC_Customer extends WC_Legacy_Customer
in package

Customer class.

Table of Contents

CLONE_MODE_CACHE  = 'cache'
Clone mode constant: Cache mode preserves meta IDs.
CLONE_MODE_DUPLICATE  = 'duplicate'
Clone mode constant: Duplicate mode clears meta IDs (default, for backward compatibility).
$cache_group  : string
Stores meta in cache for future reads.
$calculated_shipping  : bool
Stores if user has calculated shipping in this session.
$changes  : array<string|int, mixed>
Core data changes for this object.
$clone_mode  : string
Clone mode for controlling meta ID handling during clone operations.
$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  : bool
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, WC_Meta_Data>|null
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.
$loading_default_address_fields  : bool
Whether has_full_shipping_address() is loading the default address fields, so a nested call from a filter callback does not load them again.
__clone()  : mixed
When the object is cloned, make sure meta is cloned 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_cache()  : void
Delete this object's cached raw meta data entry, if a cache group is set.
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|false
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_clone_mode()  : string
Get the current clone mode.
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_full_shipping_address()  : bool
Checks whether the address is "full" in the sense that it contains all required fields to calculate shipping rates.
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()  : void
Set billing_address_1.
set_billing_address_1()  : void
Set billing_address_1.
set_billing_address_2()  : void
Set billing_address_2.
set_billing_address_to_base()  : void
Set customer address to match shop base address.
set_billing_city()  : void
Set billing_city.
set_billing_company()  : void
Set billing_company.
set_billing_country()  : void
Set billing_country.
set_billing_email()  : void
Set billing_email.
set_billing_first_name()  : void
Set billing_first_name.
set_billing_last_name()  : void
Set billing_last_name.
set_billing_location()  : void
Sets all address info at once.
set_billing_phone()  : void
Set billing_phone.
set_billing_postcode()  : void
Set billing_postcode.
set_billing_state()  : void
Set billing_state.
set_calculated_shipping()  : void
Calculated shipping?
set_city()  : mixed
Legacy set city.
set_clone_mode()  : mixed
Set the clone mode.
set_country()  : mixed
Legacy set country.
set_date_created()  : void
Set the date this customer was last updated.
set_date_modified()  : void
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()  : void
Set customer's display name.
set_email()  : void
Set customer's email.
set_first_name()  : void
Set customer's first name.
set_id()  : mixed
Set ID.
set_is_paying_customer()  : void
Set if the user a paying customer.
set_is_vat_exempt()  : void
Set if customer has tax exemption.
set_last_name()  : void
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()  : void
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()  : void
Set customer's user role(s).
set_shipping_address()  : void
Set shipping_address_1.
set_shipping_address_1()  : void
Set shipping_address_1.
set_shipping_address_2()  : void
Set shipping_address_2.
set_shipping_address_to_base()  : void
Set customer shipping address to base address.
set_shipping_city()  : void
Set shipping_city.
set_shipping_company()  : void
Set shipping_company.
set_shipping_country()  : void
Set shipping_country.
set_shipping_first_name()  : void
Set shipping_first_name.
set_shipping_last_name()  : void
Set shipping_last_name.
set_shipping_location()  : void
Sets all shipping info at once.
set_shipping_phone()  : void
Set shipping phone.
set_shipping_postcode()  : void
Set shipping_postcode.
set_shipping_state()  : void
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()  : void
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()  : void
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.

Constants

CLONE_MODE_DUPLICATE

Clone mode constant: Duplicate mode clears meta IDs (default, for backward compatibility).

public mixed CLONE_MODE_DUPLICATE = 'duplicate'
Tags
since
10.4.0

Properties

$calculated_shipping

Stores if user has calculated shipping in this session.

protected bool $calculated_shipping = alse

$clone_mode

Clone mode for controlling meta ID handling during clone operations.

protected string $clone_mode = self::CLONE_MODE_DUPLICATE
Tags
since
10.4.0

$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 = ''

$loading_default_address_fields

Whether has_full_shipping_address() is loading the default address fields, so a nested call from a filter callback does not load them again.

private static bool $loading_default_address_fields = alse

Methods

__clone()

When the object is cloned, make sure meta is cloned correctly.

public __clone() : mixed

Meta ID handling depends on the clone mode:

  • CLONE_MODE_DUPLICATE (default): Forces reading of Meta and clears meta IDs for duplication (backward compatible).
  • CLONE_MODE_CACHE: Preserves meta IDs for caching purposes.
Tags
since
3.0.2
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
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
bool — result

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_cache()

Delete this object's cached raw meta data entry, if a cache group is set.

public delete_meta_cache() : void

Counterpart to prime_raw_meta_data_cache(): it removes the entry stored under this object's own cache group (for example 'orders' for WC_Abstract_Order), so the next read_meta_data() misses the cache and re-reads from the database. Used to recover from a corrupt persistent object cache entry.

Tags
since
11.0.0
Return values
void —

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
string — Meta cache key.

get_avatar_url()

Return this customer's avatar.

public get_avatar_url() : string|false
Tags
since
3.0.0
Return values
string|false —

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_clone_mode()

Get the current clone mode.

public get_clone_mode() : string
Tags
since
10.4.0
Return values
string — The current clone mode (one of the CLONE_MODE_* constants).

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|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
since
3.0.0
Return values
WC_DateTime|null — object 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_full_shipping_address()

Checks whether the address is "full" in the sense that it contains all required fields to calculate shipping rates.

public has_full_shipping_address() : bool

This method uses the current country's locale to determine if a field is required, or falls back to the default locale if there's no country-specific setting for that field.

This method is only used internally by StoreAPI, and not by the classic/shortcode checkout.

Tags
since
9.8.0
Return values
bool — Whether the customer has a full shipping address (city, state, postcode, country). Only required fields are checked based on the country locale.

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) : void
Parameters
$value : string

Billing address line 1.

Return values
void —

set_billing_address_1()

Set billing_address_1.

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

Billing address line 1.

Return values
void —

set_billing_address_2()

Set billing_address_2.

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

Billing address line 2.

Return values
void —

set_billing_address_to_base()

Set customer address to match shop base address.

public set_billing_address_to_base() : void
Tags
since
3.0.0
Return values
void —

set_billing_city()

Set billing_city.

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

Billing city.

Return values
void —

set_billing_company()

Set billing_company.

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

Billing company.

Return values
void —

set_billing_country()

Set billing_country.

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

Billing country.

Return values
void —

set_billing_email()

Set billing_email.

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

Billing email.

Return values
void —

set_billing_first_name()

Set billing_first_name.

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

Billing first name.

Return values
void —

set_billing_last_name()

Set billing_last_name.

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

Billing last name.

Return values
void —

set_billing_location()

Sets all address info at once.

public set_billing_location(string $country[, string $state = '' ][, string $postcode = '' ][, string $city = '' ]) : void
Parameters
$country : string

Country.

$state : string = ''

State.

$postcode : string = ''

Postcode.

$city : string = ''

City.

Return values
void —

set_billing_phone()

Set billing_phone.

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

Billing phone.

Return values
void —

set_billing_postcode()

Set billing_postcode.

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

Billing postcode.

Return values
void —

set_billing_state()

Set billing_state.

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

Billing state.

Return values
void —

set_calculated_shipping()

Calculated shipping?

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

If shipping is calculated.

Return values
void —

set_clone_mode()

Set the clone mode.

public set_clone_mode(string $mode) : mixed

This controls how meta IDs are handled when the object is cloned:

  • CLONE_MODE_DUPLICATE (default): Clears meta IDs for duplication workflows
  • CLONE_MODE_CACHE: Preserves meta IDs for caching workflows
Parameters
$mode : string

One of the CLONE_MODE_* constants.

Tags
since
10.4.0
throws
InvalidArgumentException

If an invalid mode is provided.

Return values
mixed —

set_date_created()

Set the date this customer was last updated.

public set_date_created([string|int|null $date = null ]) : void
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
void —

set_date_modified()

Set the date this customer was last updated.

public set_date_modified([string|int|null $date = null ]) : void
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
void —

set_display_name()

Set customer's display name.

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

Display name.

Tags
since
3.1.0
Return values
void —

set_email()

Set customer's email.

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

Email.

Tags
since
3.0.0
Return values
void —

set_first_name()

Set customer's first name.

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

First name.

Tags
since
3.0.0
Return values
void —

set_is_paying_customer()

Set if the user a paying customer.

public set_is_paying_customer(bool $is_paying_customer) : void
Parameters
$is_paying_customer : bool

If is a paying customer.

Tags
since
3.0.0
Return values
void —

set_is_vat_exempt()

Set if customer has tax exemption.

public set_is_vat_exempt(bool $is_vat_exempt) : void
Parameters
$is_vat_exempt : bool

If is vat exempt.

Return values
void —

set_last_name()

Set customer's last name.

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

Last name.

Tags
since
3.0.0
Return values
void —

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) : void
Parameters
$password : string

Password.

Tags
since
3.0.0
Return values
void —

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) : void
Parameters
$role : mixed

User role.

Tags
since
3.0.0
Return values
void —

set_shipping_address()

Set shipping_address_1.

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

Shipping address line 1.

Return values
void —

set_shipping_address_1()

Set shipping_address_1.

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

Shipping address line 1.

Return values
void —

set_shipping_address_2()

Set shipping_address_2.

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

Shipping address line 2.

Return values
void —

set_shipping_address_to_base()

Set customer shipping address to base address.

public set_shipping_address_to_base() : void
Tags
since
3.0.0
Return values
void —

set_shipping_city()

Set shipping_city.

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

Shipping city.

Return values
void —

set_shipping_company()

Set shipping_company.

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

Shipping company.

Return values
void —

set_shipping_country()

Set shipping_country.

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

Shipping country.

Return values
void —

set_shipping_first_name()

Set shipping_first_name.

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

Shipping first name.

Return values
void —

set_shipping_last_name()

Set shipping_last_name.

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

Shipping last name.

Return values
void —

set_shipping_location()

Sets all shipping info at once.

public set_shipping_location(string $country[, string $state = '' ][, string $postcode = '' ][, string $city = '' ]) : void
Parameters
$country : string

Country.

$state : string = ''

State.

$postcode : string = ''

Postcode.

$city : string = ''

City.

Return values
void —

set_shipping_phone()

Set shipping phone.

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

Shipping phone.

Tags
since
5.6.0
Return values
void —

set_shipping_postcode()

Set shipping_postcode.

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

Shipping postcode.

Return values
void —

set_shipping_state()

Set shipping_state.

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

Shipping state.

Return values
void —

set_username()

Set customer's username.

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

Username.

Tags
since
3.0.0
Return values
void —

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
bool — true 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) : void
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
void —

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 —