Activates a loyalty program.
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:
earnPoints()
functions and switch off all the "Earn Points" and "Rewards" toggles in the Loyalty Program dashboard.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 and runs only on the backend and on dashboard pages.
function activateLoyaltyProgram(): Promise<ActivateLoyaltyProgramResponse>;
import { programs } from "wix-loyalty.v2";
export async function myActivateLoyaltyProgramFunction() {
const elevatedActivateProgram = wixAuth.elevate(
programs.activateLoyaltyProgram,
);
try {
const myLoyaltyProgram = await elevatedActivateProgram();
const name = myLoyaltyProgram.loyaltyProgram.name;
const status = myLoyaltyProgram.loyaltyProgram.status;
console.log("Success! The status of your loyalty program is:", status);
return myLoyaltyProgram;
} catch (error) {
console.error(error);
}
}
/* Promise resolves to:
* {
* "loyaltyProgram": {
* "name": "Star Loyalty Program",
* "pointDefinition": {
* "customName": "Stars",
* "icon": "shapes/39dce0a5d1ce498f95526b1390eaf585.svg",
* },
* "status": "ACTIVE",
* "_createdDate": "2022-05-22T08:18:32.186Z",
* "_updatedDate": "2022-05-25T10:36:32.430Z"
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.