PHP Class WC_Customer

Author: WooThemes
Inheritance: extends WC_Legacy_Customer
Mostra file Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$calculated_shipping string Stores if user has calculated shipping in this session.
$data array Stores customer data.
$is_vat_exempt string Stores if user is VAT exempt for this session.
$password string Stores a password if this needs to be changed. Write-only and hidden from _data.

Public Methods

Method Description
__construct ( WC_Customer | integer $data, boolean $is_session = false ) Load customer data based on how WC_Customer is called.
delete_and_reassign ( integer $reassign = null ) : boolean Delete a customer and reassign posts.
get_avatar_url ( ) : string Return this customer's avatar.
get_billing_address ( string $context = 'view' ) : string Get billing_address_1.
get_billing_address_1 ( string $context = 'view' ) : string Get billing_address_1.
get_billing_address_2 ( string $context = 'view' ) : string Get billing_address_2.
get_billing_city ( string $context = 'view' ) : string Get billing_city.
get_billing_company ( string $context = 'view' ) : string Get billing_company.
get_billing_country ( string $context = 'view' ) : string Get billing_country.
get_billing_email ( string $context = 'view' ) : string Get billing_email.
get_billing_first_name ( string $context = 'view' ) : string Get billing_first_name.
get_billing_last_name ( string $context = 'view' ) : string Get billing_last_name.
get_billing_phone ( string $context = 'view' ) : string Get billing_phone.
get_billing_postcode ( string $context = 'view' ) : string Get billing_postcode.
get_billing_state ( string $context = 'view' ) : string Get billing_state.
get_calculated_shipping ( ) : boolean Has customer calculated shipping?
get_date_created ( string $context = 'view' ) : integer Return the date this customer was created.
get_date_modified ( string $context = 'view' ) : integer Return the date this customer was last updated.
get_downloadable_products ( ) : array Gets a customer's downloadable products.
get_email ( string $context = 'view' ) : string Return the customer's email.
get_first_name ( string $context = 'view' ) : string Return customer's first name.
get_is_paying_customer ( string $context = 'view' ) : boolean Is the user a paying customer?
get_is_vat_exempt ( ) : boolean Get if customer is VAT exempt?
get_last_name ( string $context = 'view' ) : string Return customer's last name.
get_last_order ( ) : WC_Order | false Gets the customers last order.
get_order_count ( ) : integer Return the number of orders this customer has.
get_password ( ) : string Get password (only used when updating the user object).
get_role ( string $context = 'view' ) : string Return customer's user role.
get_shipping_address ( string $context = 'view' ) : string Get shipping_address_1.
get_shipping_address_1 ( string $context = 'view' ) : string Get shipping_address_1.
get_shipping_address_2 ( string $context = 'view' ) : string Get shipping_address_2.
get_shipping_city ( string $context = 'view' ) : string Get shipping_city.
get_shipping_company ( string $context = 'view' ) : string Get shipping_company.
get_shipping_country ( string $context = 'view' ) : string Get shipping_country.
get_shipping_first_name ( string $context = 'view' ) : string Get shipping_first_name.
get_shipping_last_name ( string $context = 'view' ) : string Get shipping_last_name.
get_shipping_postcode ( string $context = 'view' ) : string Get shipping_postcode.
get_shipping_state ( string $context = 'view' ) : string Get shipping_state.
get_taxable_address ( ) : array Get taxable address.
get_total_spent ( ) : float Return how much money this customer has spent.
get_username ( string $context = 'view' ) : string Return the customer's username.
has_calculated_shipping ( ) : boolean Has calculated shipping?
is_customer_outside_base ( ) : boolean Is customer outside base country (for tax purposes)?
is_vat_exempt ( ) : boolean Is customer VAT exempt?
set_billing_address ( string $value ) Set billing_address_1.
set_billing_address_1 ( string $value ) Set billing_address_1.
set_billing_address_2 ( string $value ) Set billing_address_2.
set_billing_address_to_base ( ) Set customer address to match shop base address.
set_billing_city ( string $value ) Set billing_city.
set_billing_company ( string $value ) Set billing_company.
set_billing_country ( string $value ) Set billing_country.
set_billing_email ( string $value ) Set billing_email.
set_billing_first_name ( string $value ) Set billing_first_name.
set_billing_last_name ( string $value ) Set billing_last_name.
set_billing_location ( string $country, string $state, string $postcode = '', string $city = '' ) Sets all address info at once.
set_billing_phone ( string $value ) Set billing_phone.
set_billing_postcode ( string $value ) Set billing_postcode.
set_billing_state ( string $value ) Set billing_state.
set_calculated_shipping ( boolean $calculated = true ) Calculated shipping?
set_date_created ( integer $timestamp ) Set the date this customer was last updated.
set_date_modified ( integer $timestamp ) Set the date this customer was last updated.
set_email ( string $value ) Set customer's email.
set_first_name ( string $first_name ) Set customer's first name.
set_is_paying_customer ( boolean $is_paying_customer ) Set if the user a paying customer.
set_is_vat_exempt ( boolean $is_vat_exempt ) Set if customer has tax exemption.
set_last_name ( string $last_name ) Set customer's last name.
set_password ( string $password ) Set customer's password.
set_role ( mixed $role ) Set customer's user role(s).
set_shipping_address ( string $value ) Set shipping_address_1.
set_shipping_address_1 ( string $value ) Set shipping_address_1.
set_shipping_address_2 ( string $value ) Set shipping_address_2.
set_shipping_address_to_base ( ) Set customer shipping address to base address.
set_shipping_city ( string $value ) Set shipping_city.
set_shipping_company ( string $value ) Set shipping_company.
set_shipping_country ( string $value ) Set shipping_country.
set_shipping_first_name ( string $value ) Set shipping_first_name.
set_shipping_last_name ( string $value ) Set shipping_last_name.
set_shipping_location ( string $country, string $state = '', string $postcode = '', string $city = '' ) Sets all shipping info at once.
set_shipping_postcode ( string $value ) Set shipping_postcode.
set_shipping_state ( string $value ) Set shipping_state.
set_username ( string $username ) Set customer's username.

Protected Methods

Method Description
get_address_prop ( string $prop, string $address = 'billing', string $context = 'view' ) : mixed Gets a prop for a getter method.
get_hook_prefix ( ) : string Prefix for action and filter hooks on data.
set_address_prop ( string $prop, string $address = 'billing', mixed $value ) Sets a prop for a setter method.

Method Details

__construct() public method

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.
public __construct ( WC_Customer | integer $data, boolean $is_session = false )
$data WC_Customer | integer Customer ID or data.
$is_session boolean True if this is the customer session

delete_and_reassign() public method

.
Since: 2.7.0
public delete_and_reassign ( integer $reassign = null ) : boolean
$reassign integer Reassign posts and links to new User ID.
return boolean

get_address_prop() protected method

Gets a prop for a getter method.
Since: 2.7.0
protected get_address_prop ( string $prop, string $address = 'billing', string $context = 'view' ) : mixed
$prop string Name of prop to get.
$address string billing or shipping.
$context string What the value is for. Valid values are view and edit.
return mixed

get_avatar_url() public method

Return this customer's avatar.
Since: 2.7.0
public get_avatar_url ( ) : string
return string

get_billing_address() public method

Get billing_address_1.
public get_billing_address ( string $context = 'view' ) : string
$context string
return string

get_billing_address_1() public method

Get billing_address_1.
public get_billing_address_1 ( string $context = 'view' ) : string
$context string
return string

get_billing_address_2() public method

Get billing_address_2.
public get_billing_address_2 ( string $context = 'view' ) : string
$context string
return string $value

get_billing_city() public method

Get billing_city.
public get_billing_city ( string $context = 'view' ) : string
$context string
return string $value

get_billing_company() public method

Get billing_company.
public get_billing_company ( string $context = 'view' ) : string
$context string
return string

get_billing_country() public method

Get billing_country.
public get_billing_country ( string $context = 'view' ) : string
$context string
return string

get_billing_email() public method

Get billing_email.
public get_billing_email ( string $context = 'view' ) : string
$context string
return string

get_billing_first_name() public method

Get billing_first_name.
public get_billing_first_name ( string $context = 'view' ) : string
$context string
return string

get_billing_last_name() public method

Get billing_last_name.
public get_billing_last_name ( string $context = 'view' ) : string
$context string
return string

get_billing_phone() public method

Get billing_phone.
public get_billing_phone ( string $context = 'view' ) : string
$context string
return string

get_billing_postcode() public method

Get billing_postcode.
public get_billing_postcode ( string $context = 'view' ) : string
$context string
return string

get_billing_state() public method

Get billing_state.
public get_billing_state ( string $context = 'view' ) : string
$context string
return string

get_calculated_shipping() public method

Has customer calculated shipping?

get_date_created() public method

Return the date this customer was created.
Since: 2.7.0
public get_date_created ( string $context = 'view' ) : integer
$context string
return integer

get_date_modified() public method

Return the date this customer was last updated.
Since: 2.7.0
public get_date_modified ( string $context = 'view' ) : integer
$context string
return integer

get_downloadable_products() public method

Gets a customer's downloadable products.
public get_downloadable_products ( ) : array
return array Array of downloadable products

get_email() public method

Return the customer's email.
Since: 2.7.0
public get_email ( string $context = 'view' ) : string
$context string
return string

get_first_name() public method

Return customer's first name.
Since: 2.7.0
public get_first_name ( string $context = 'view' ) : string
$context string
return string

get_hook_prefix() protected method

Prefix for action and filter hooks on data.
Since: 2.7.0
protected get_hook_prefix ( ) : string
return string

get_is_paying_customer() public method

Is the user a paying customer?
Since: 2.7.0
public get_is_paying_customer ( string $context = 'view' ) : boolean
$context string
return boolean

get_is_vat_exempt() public method

Get if customer is VAT exempt?
Since: 2.7.0
public get_is_vat_exempt ( ) : boolean
return boolean

get_last_name() public method

Return customer's last name.
Since: 2.7.0
public get_last_name ( string $context = 'view' ) : string
$context string
return string

get_last_order() public method

Gets the customers last order.
public get_last_order ( ) : WC_Order | false
return WC_Order | false

get_order_count() public method

Return the number of orders this customer has.
public get_order_count ( ) : integer
return integer

get_password() public method

Get password (only used when updating the user object).
public get_password ( ) : string
return string

get_role() public method

Return customer's user role.
Since: 2.7.0
public get_role ( string $context = 'view' ) : string
$context string
return string

get_shipping_address() public method

Get shipping_address_1.
public get_shipping_address ( string $context = 'view' ) : string
$context string
return string

get_shipping_address_1() public method

Get shipping_address_1.
public get_shipping_address_1 ( string $context = 'view' ) : string
$context string
return string

get_shipping_address_2() public method

Get shipping_address_2.
public get_shipping_address_2 ( string $context = 'view' ) : string
$context string
return string

get_shipping_city() public method

Get shipping_city.
public get_shipping_city ( string $context = 'view' ) : string
$context string
return string

get_shipping_company() public method

Get shipping_company.
public get_shipping_company ( string $context = 'view' ) : string
$context string
return string

get_shipping_country() public method

Get shipping_country.
public get_shipping_country ( string $context = 'view' ) : string
$context string
return string

get_shipping_first_name() public method

Get shipping_first_name.
public get_shipping_first_name ( string $context = 'view' ) : string
$context string
return string

get_shipping_last_name() public method

Get shipping_last_name.
public get_shipping_last_name ( string $context = 'view' ) : string
$context string
return string

get_shipping_postcode() public method

Get shipping_postcode.
public get_shipping_postcode ( string $context = 'view' ) : string
$context string
return string

get_shipping_state() public method

Get shipping_state.
public get_shipping_state ( string $context = 'view' ) : string
$context string
return string

get_taxable_address() public method

Get taxable address.
public get_taxable_address ( ) : array
return array

get_total_spent() public method

Return how much money this customer has spent.
public get_total_spent ( ) : float
return float

get_username() public method

Return the customer's username.
Since: 2.7.0
public get_username ( string $context = 'view' ) : string
$context string
return string

has_calculated_shipping() public method

Has calculated shipping?

is_customer_outside_base() public method

Is customer outside base country (for tax purposes)?

is_vat_exempt() public method

Is customer VAT exempt?
public is_vat_exempt ( ) : boolean
return boolean

set_address_prop() protected method

Sets a prop for a setter method.
Since: 2.7.0
protected set_address_prop ( string $prop, string $address = 'billing', mixed $value )
$prop string Name of prop to set.
$address string Name of address to set. billing or shipping.
$value mixed Value of the prop.

set_billing_address() public method

Set billing_address_1.
public set_billing_address ( string $value )
$value string

set_billing_address_1() public method

Set billing_address_1.
public set_billing_address_1 ( string $value )
$value string

set_billing_address_2() public method

Set billing_address_2.
public set_billing_address_2 ( string $value )
$value string

set_billing_address_to_base() public method

Set customer address to match shop base address.
Since: 2.7.0

set_billing_city() public method

Set billing_city.
public set_billing_city ( string $value )
$value string

set_billing_company() public method

Set billing_company.
public set_billing_company ( string $value )
$value string

set_billing_country() public method

Set billing_country.
public set_billing_country ( string $value )
$value string

set_billing_email() public method

Set billing_email.
public set_billing_email ( string $value )
$value string

set_billing_first_name() public method

Set billing_first_name.
public set_billing_first_name ( string $value )
$value string

set_billing_last_name() public method

Set billing_last_name.
public set_billing_last_name ( string $value )
$value string

set_billing_location() public method

Sets all address info at once.
public set_billing_location ( string $country, string $state, string $postcode = '', string $city = '' )
$country string
$state string
$postcode string
$city string

set_billing_phone() public method

Set billing_phone.
public set_billing_phone ( string $value )
$value string

set_billing_postcode() public method

Set billing_postcode.
public set_billing_postcode ( string $value )
$value string

set_billing_state() public method

Set billing_state.
public set_billing_state ( string $value )
$value string

set_calculated_shipping() public method

Calculated shipping?
public set_calculated_shipping ( boolean $calculated = true )
$calculated boolean

set_date_created() public method

Set the date this customer was last updated.
Since: 2.7.0
public set_date_created ( integer $timestamp )
$timestamp integer

set_date_modified() public method

Set the date this customer was last updated.
Since: 2.7.0
public set_date_modified ( integer $timestamp )
$timestamp integer

set_email() public method

Set customer's email.
Since: 2.7.0
public set_email ( string $value )
$value string

set_first_name() public method

Set customer's first name.
Since: 2.7.0
public set_first_name ( string $first_name )
$first_name string

set_is_paying_customer() public method

Set if the user a paying customer.
Since: 2.7.0
public set_is_paying_customer ( boolean $is_paying_customer )
$is_paying_customer boolean

set_is_vat_exempt() public method

Set if customer has tax exemption.
public set_is_vat_exempt ( boolean $is_vat_exempt )
$is_vat_exempt boolean

set_last_name() public method

Set customer's last name.
Since: 2.7.0
public set_last_name ( string $last_name )
$last_name string

set_password() public method

Set customer's password.
Since: 2.7.0
public set_password ( string $password )
$password string

set_role() public method

Set customer's user role(s).
Since: 2.7.0
public set_role ( mixed $role )
$role mixed

set_shipping_address() public method

Set shipping_address_1.
public set_shipping_address ( string $value )
$value string

set_shipping_address_1() public method

Set shipping_address_1.
public set_shipping_address_1 ( string $value )
$value string

set_shipping_address_2() public method

Set shipping_address_2.
public set_shipping_address_2 ( string $value )
$value string

set_shipping_address_to_base() public method

Set customer shipping address to base address.
Since: 2.7.0

set_shipping_city() public method

Set shipping_city.
public set_shipping_city ( string $value )
$value string

set_shipping_company() public method

Set shipping_company.
public set_shipping_company ( string $value )
$value string

set_shipping_country() public method

Set shipping_country.
public set_shipping_country ( string $value )
$value string

set_shipping_first_name() public method

Set shipping_first_name.
public set_shipping_first_name ( string $value )
$value string

set_shipping_last_name() public method

Set shipping_last_name.
public set_shipping_last_name ( string $value )
$value string

set_shipping_location() public method

Sets all shipping info at once.
public set_shipping_location ( string $country, string $state = '', string $postcode = '', string $city = '' )
$country string
$state string
$postcode string
$city string

set_shipping_postcode() public method

Set shipping_postcode.
public set_shipping_postcode ( string $value )
$value string

set_shipping_state() public method

Set shipping_state.
public set_shipping_state ( string $value )
$value string

set_username() public method

Set customer's username.
Since: 2.7.0
public set_username ( string $username )
$username string

Property Details

$calculated_shipping protected_oe property

Stores if user has calculated shipping in this session.
protected string $calculated_shipping
return string

$data protected_oe property

Stores customer data.
protected array $data
return array

$is_vat_exempt protected_oe property

Stores if user is VAT exempt for this session.
protected string $is_vat_exempt
return string

$password protected_oe property

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