The Customer Object
A customer is a WordPress user enriched with commerce data — billing/shipping addresses and order aggregates. StoreEngine wraps this in StoreEngine\Classes\Customer.
Loading a customer
Construct with a WordPress user id and call get() to hydrate. Passing 0 (the default) yields a blank/guest customer.
use StoreEngine\Classes\Customer;
$customer = new Customer( get_current_user_id() );
$customer->get(); // load stored data
echo $customer->get_display_name();
echo $customer->get_email();
The second constructor argument, bool $in_session, ties the customer to the current front-end session (used during checkout for guests):
$customer = new Customer( 0, true ); // session-backed guest customer
There is no storeengine_get_customer() global — instantiate Customer directly with the user id.
Profile getters
| Method | Returns |
|---|---|
get_id() | WordPress user id. |
get_wp_user() | The underlying WP_User (nullable). |
get_email() | Account email. |
get_full_name() | First + last name. |
get_display_name() | Display name. |
get_total_orders() | Number of orders placed. |
get_total_spent() | Lifetime spend. |
$orders = $customer->get_total_orders();
$spent = $customer->get_total_spent();
$user = $customer->get_wp_user(); // ?WP_User
Billing and shipping
Individual field getters follow the get_billing_* / get_shipping_* convention:
$country = $customer->get_billing_country();
$postcode = $customer->get_shipping_postcode();
$phone = $customer->get_billing_phone();
Set a whole location at once, or set individual fields, then save():
// set_billing_location( string $country, string $state = '', string $postcode = '', string $city = '' )
$customer->set_billing_location( 'US', 'CA', '94016', 'San Francisco' );
$customer->set_shipping_location( 'US', 'CA', '94016', 'San Francisco' );
// individual setters also exist: set_billing_first_name(), set_shipping_address_1(), etc.
$customer->save(); // persist changes
Seed the billing address from the store's base location:
$customer->set_billing_address_to_base();
$customer->save();
Persisting
save() writes any pending profile/address changes back to storage. Always call it after mutating a customer:
$customer->set_billing_phone( '+1 555 0100' );
$customer->save();
See also
- Orders — orders reference the customer's user id.
- Subscriptions — subscriptions belong to a customer.
- REST API › Customers — the customer HTTP API.
- REST API › Me — the current-customer storefront endpoint.