activateLoyaltyProgram( )
Activates a loyalty program.
Description
The activateLoyaltyProgram()
function returns a Promise that resolves when the status of the loyalty program is successfully changed to "ACTIVE"
.
Before you begin, a Wix Loyalty Program must first be installed through your dashboard or through the Wix App Market. Initially when a loyalty program is installed, the status is set to "DRAFT"
. You can change the program's status to "ACTIVE"
with this function or through your dashboard. A site's customers can only earn or redeem points while the program status is "ACTIVE"
.
This function updates only the status of a loyalty program, to make other updates to the program, use the updateLoyaltyProgram()
function.
To temporarily pause your loyalty program you must follow three steps:
- Remove all
earnPoints()
functions and switch off all the "Earn Points" and "Rewards" toggles in the Loyalty Program dashboard. - Hide the loyalty page from your site.
- Delete the My Rewards page from the Member pages.
See Pausing Your Loyalty Program for more information.
Note: Only visitors with Manage Loyalty permissions can activate a loyalty program. You can override the permissions with the
wix-auth
elevate()
function.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function activateLoyaltyProgram(): Promise<ActivateLoyaltyProgramResponse>
activateLoyaltyProgram Parameters
This function does not take any parameters.
Returns
Return Type:
NAME
TYPE
DESCRIPTION
Activated loyalty program.
Was this helpful?
1import { programs } from 'wix-loyalty.v2';23export async function myActivateLoyaltyProgramFunction() {45 const elevatedActivateProgram = wixAuth.elevate(programs.activateLoyaltyProgram)67 try {8 const myLoyaltyProgram = await elevatedActivateProgram();910 const name = myLoyaltyProgram.loyaltyProgram.name;11 const status = myLoyaltyProgram.loyaltyProgram.status;1213 console.log('Success! The status of your loyalty program is:', status);1415 return myLoyaltyProgram;16 } catch (error) {17 console.error(error);18 }19}2021/* Promise resolves to:22 * {23 * "loyaltyProgram": {24 * "name": "Star Loyalty Program",25 * "pointDefinition": {26 * "customName": "Stars",27 * "icon": "shapes/39dce0a5d1ce498f95526b1390eaf585.svg",28 * },29 * "status": "ACTIVE",30 * "_createdDate": "2022-05-22T08:18:32.186Z",31 * "_updatedDate": "2022-05-25T10:36:32.430Z"32 * }33 * }34 */35
1import { Permissions, webMethod } from 'wix-web-module';2import { programs } from 'wix-loyalty.v2';3import { elevate } from 'wix-auth';45export const myActivateLoyaltyProgramFunction = webMethod(Permissions.Anyone, async () => {67 const elevatedActivateProgram = elevate(programs.activateLoyaltyProgram)89 try {10 const myLoyaltyProgram = await elevatedActivateProgram();1112 const name = myLoyaltyProgram.loyaltyProgram.name;13 const status = myLoyaltyProgram.loyaltyProgram.status;1415 console.log('Success! The status of your loyalty program is:', status);1617 return myLoyaltyProgram;18 } catch (error) {19 console.error(error);20 }21});2223/* Promise resolves to:24 * {25 * "loyaltyProgram": {26 * "name": "Star Loyalty Program",27 * "pointDefinition": {28 * "customName": "Stars",29 * "icon": "shapes/39dce0a5d1ce498f95526b1390eaf585.svg",30 * },31 * "status": "ACTIVE",32 * "_createdDate": "2022-05-22T08:18:32.186Z",33 * "_updatedDate": "2022-05-25T10:36:32.430Z"34 * }35 * }36 */37