Methods for customer management

JS API methods are used for client-side management of customers currently logged in to the store. Get customer details like email, group ID, and shipping address, set their tracking consent, and create custom sign-out flows.

Enable JS API on the storefront

The methods listed below require JS API to be loaded on the page. Read more on how to enable JS API.

Ecwid.Customer.get(customer)

This method receives all data on the customer currently logged in to the store.

Request example:

Ecwid.Customer.get(function(customer) { 
  console.log(customer.email);
});

// prints
// [email protected]

Fields available in the returned customer object:

NameTypeDescription
billingPersonobject{Person}Customer details including address and contact details (name and phone).
emailStringCustomer's email.
idNumberCustomer ID.
membershipobject{CustomerGroup}Customer group details. Available only if a customer belongs to a customer group.
ownerIdnumberEcwid Store ID.
registeredUNIX TimestampCustomer's registration date.
shippingAddressesarray{ShippingAddress}Customer’s address book.

Person

NameTypeDescription
namestringCustomer's name.
companyNamestring, optionalCompany name of a customer, if available.
streetstring, optionalShipping/billing address. Street.
citystring, optionalShipping/billing address. City.
countryNamestring, optionalShipping/billing address. Country name.
countryCodestring, optionalShipping/billing address. Country code in ISO 3166-2.
postalCodestring, optionalShipping/billing address. ZIP code.
stateOrProvinceCodestring, optionalShipping/billing address. State code ISO 3166-2.
phonestring, optionalCustomer's phone number, if available.

CustomerGroup

NameTypeDescription
idnumberCustomer group ID.
namestringCustomer group name.
owneridnumberEcwid store ID

ShippingAddress

NameTypeDescription
idintegerSaved shipping address ID.
personobject{Person}Customer's shipping address details.

Ecwid.getVisitorLocation();

This method gets the customer's location based on their shipping or billing address, or IP.

Request example:

Ecwid.getVisitorLocation();

// {countryCode: 'US', stateCode: 'NE', source: 'SHIPPING_ADDRESS'}

Available fields

NameTypeDescription
countryCodestringCountry code (null if not found)
stateCodestringState code (null if not found)
sourcestringThe source of the received country code and state code. Possible values: 'SHIPPING_ADDRESS’, ‘BILLING_ADDRESS’, 'IP_ADDRESS’.

Ecwid.Customer.signout(success,error)

This method signs out customer from their account.

Request example:

Ecwid.Customer.signOut(function(success,error) { 
  if (success == true) {
      console.log("Customer signed out");
  } else {
      console.log("Signout failed. Error message: " + error);
  }
});

// prints
// Customer signed out

Fields available in the returned object:

NameTypeDescription
successbooleanIs true if a customer was signed out, false otherwise.
errorstringError message. Has value only if success is false