Ecwid.Cart.setAddress

Set shipping address for customer in storefront.

You can use it to prefill and hide fields in checkout process to simplify it. If you specify some fields only (name, for example), then Ecwid will reset all other fields and they will become empty. So if you need to update only some fields, make sure to send them in your function call as well as the updated values.

When function is called, Ecwid will set the 'My shipping address is the same as the billing address' flag to true automatically. Full function call example:

Ecwid.Cart.setAddress({
  "name": "John Carmichael",
  "companyName": "Cool Slippers",
  "street": "5th Ave",
  "city": "New York",
  "countryName": "United States",
  "postalCode": "10002",
  "stateOrProvinceCode": "NY",
  "phone": "+1 234 523 11 42"
  },
  function(){
    console.log('Address successfully set')
  },
  function(){
    console.log('Error setting the address');
  }
);

Subscribe to the Ecwid.OnAPILoaded JS API event to ensure availability of this function.

Fields:

NameTypeDescription
address<Person>Customer's shipping address details
successCallbackfunctionSuccess callback function
errorCallbackfunctionError callback function

Person fields:

NameTypeDescription
namestringCustomer's name
companyNamestringCustomer's company name
streetstringCustomer's street address. Use \n to place text in Address Line 2
citystringCustomer's city
countryNamestringCustomer's country name. countryCode can be used instead
countryCodestringCustomer's country code. countryName can be used instead
postalCodestringCustomer's zip code
stateOrProvinceCodestringCustomer's state or provice code. Ignored if countryCode or countryName are not specified.
phonestringCustomer's phone number

📘

Parameters in bold are mandatory

errorCallback structure is: errorCallback(errCode, errMsg)

NameTypeDescription
errCodenumberError code
errMsgstringError message

Errors

Error codeError message
0Missing argument