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:
Name | Type | Description |
---|---|---|
address | <Person> | Customer's shipping address details |
successCallback | function | Success callback function |
errorCallback | function | Error callback function |
Person fields:
Name | Type | Description |
---|---|---|
name | string | Customer's name |
companyName | string | Customer's company name |
street | string | Customer's street address. Use \n to place text in Address Line 2 |
city | string | Customer's city |
countryName | string | Customer's country name. countryCode can be used instead |
countryCode | string | Customer's country code. countryName can be used instead |
postalCode | string | Customer's zip code |
stateOrProvinceCode | string | Customer's state or provice code. Ignored if countryCode or countryName are not specified. |
phone | string | Customer's phone number |
Parameters in bold are mandatory
errorCallback
structure is: errorCallback(errCode, errMsg)
Name | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | Error message |
Errors
Error code | Error message |
---|---|
0 | Missing argument |