Skip to main content

Overview

The WC_Customer class represents a customer in WooCommerce. It manages customer data including billing/shipping addresses, user account linkage, and session data for guest customers.
The WC_Customer class works with both registered users and guest customers. For registered users, data is stored in the database. For guests, data is stored in the session.

Getting a Customer

Customer Data Structure

Basic Information

int
Customer ID (WordPress user ID)
string
Customer email address
string
Customer first name
string
Customer last name
string
Customer username
WC_DateTime
Date customer account was created
WC_DateTime
Date customer data was last modified

Billing Address

array
Billing address fields:
  • first_name
  • last_name
  • company
  • address_1
  • address_2
  • city
  • state
  • postcode
  • country
  • email
  • phone

Shipping Address

array
Shipping address fields:
  • first_name
  • last_name
  • company
  • address_1
  • address_2
  • city
  • state
  • postcode
  • country

Common Methods

Getting Customer Data

Setting Customer Data

Always call $customer->save() after making changes to persist them.

Creating a New Customer

Working with Addresses

Getting Full Addresses

Formatted Addresses

Customer Orders

Getting Customer Orders

Customer Spending Statistics

Customer Metadata

Session Management (Guest Customers)

Current Session Customer

Checking Guest vs Registered

Customer Roles

Checking Customer Role

Adding Customer Role

Downloadable Products

Customer Downloads

Helper Functions

Get Customer by Email

Check if Email Exists

Delete Customer

Hooks

Customer Save Hooks

Customer Data Filters

Best Practices

Use WC()->customer

For the current session customer, use WC()->customer.

Save Changes

Always call $customer->save() after modifications.

Handle Guests

Check $customer->get_id() > 0 to distinguish registered vs guest.

Validate Email

Always validate and sanitize email addresses before setting.

Additional Resources