Search.../

setDefaultLocation( )

Developer Preview

Sets a new default location.

Description

The setDefaultLocation() function returns a Promise that resolves to the new default location.

Notes:

  • There can be only one default location per site.
  • The setDefaultLocation() function changes the value of the default property of both the new and old default locations objects.
  • The default location can't be archived.
Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function setDefaultLocation(_id: string): Promise<SetDefaultLocationResponse>

setDefaultLocation Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the location to set as the default location.

Returns

Return Type:

Promise<
SetDefaultLocationResponse
>
NAME
TYPE
DESCRIPTION
location
Location

New default location.

Was this helpful?

Set the default location (dashboard page code)

Copy Code
1import { locations } from 'wix-business-tools.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample _id value: '0a965e36-4071-4df0-905b-75458817430a' */
5
6export async function changeDefaultLocation(_id) {
7 try {
8 const elevatedSetDefaultLocation = elevate(locations.setDefaultLocation);
9 const myDefaultLocation = await elevatedSetDefaultLocation(_id);
10 console.log('Default location has been changed to:', myDefaultLocation);
11
12 return myDefaultLocation;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17}
18
19/* Promise resolves to:
20 * {
21 * location: {
22 * "_id": "0a965e36-4071-4df0-905b-75458817430a",
23 * "address": {
24 * "streetAddress": {
25 * "apt": "34",
26 * "name": "Musterstraße",
27 * "number": "5"
28 * },
29 * "city": "Berlin",
30 * "postalCode": "53782"
31 * },
32 * "archived": false,
33 * "default": true,
34 * "description": "Our brand new store in Germany",
35 * "email": "store@example.com",
36 * "name": "Germany Store",
37 * "phone": "0208 209 9087",
38 * "revision": "2",
39 * "status": "ACTIVE",
40 * "timeZone": "Europe/Berlin"
41 * }
42 * }
43 */
44
Set the default location (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { locations } from 'wix-business-tools.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample _id value: '0a965e36-4071-4df0-905b-75458817430a' */
6
7export const changeDefaultLocation = webMethod(Permissions.Anyone, async (_id) => {
8 try {
9 const elevatedSetDefaultLocation = elevate(locations.setDefaultLocation);
10 const myDefaultLocation = await elevatedSetDefaultLocation(_id);
11 console.log('Default location has been changed to:', myDefaultLocation);
12
13 return myDefaultLocation;
14 } catch (error) {
15 console.error(error);
16 // Handle the error
17 }
18});
19
20/* Promise resolves to:
21 * {
22 * location: {
23 * "_id": "0a965e36-4071-4df0-905b-75458817430a",
24 * "address": {
25 * "streetAddress": {
26 * "apt": "34",
27 * "name": "Musterstraße",
28 * "number": "5"
29 * },
30 * "city": "Berlin",
31 * "postalCode": "53782"
32 * },
33 * "archived": false,
34 * "default": true,
35 * "description": "Our brand new store in Germany",
36 * "email": "store@example.com",
37 * "name": "Germany Store",
38 * "phone": "0208 209 9087",
39 * "revision": "2",
40 * "status": "ACTIVE",
41 * "timeZone": "Europe/Berlin"
42 * }
43 * }
44 */
45