Setting the file. One moment.
Subchapter 2.75
references/service-plugin/DISCOUNT-TRIGGERS.mdMarkdown3 KBView on GitHub
The Custom Triggers SPI allows you to define custom conditions that can trigger discounts in the Wix eCommerce system. You can create time-based triggers, product-based triggers, or any custom logic.
| Handler | Description |
|---|---|
getEligibleTriggers | Evaluate current conditions and return which triggers are active |
listTriggers | Return the list of all available custom triggers |
Before implementing, call ReadFullDocsMethodSchema on each docs URL to get the full request/response types.
This example defines two custom triggers: a time-based “Happy Hour” trigger and a product-type-based “Digital Sale” trigger.
import { customTriggers } from "@wix/ecom/service-plugins";
customTriggers.provideHandlers({
getEligibleTriggers: async (payload) => {
const { request, metadata } = payload;
// Use the `request` and `metadata` received from Wix and
// apply custom logic.
return {
// Return your response exactly as documented to integrate with Wix.
// Return value example:
eligibleTriggers: [
{
customTriggerId: "my-happy-hour-trigger",
identifier: "123",
},
{
customTriggerId: "my-digital-sale-trigger",
identifier: "234",
},
],
};
},
listTriggers: async (payload) => {
const { request, metadata } = payload;
// Use the `request` and `metadata` received from Wix and
// apply custom logic.
return {
// Return your response exactly as documented to integrate with Wix.
// Return value example:
customTriggers: [
{
_id: "my-happy-hour-trigger",
name: "Happy Hour 16:00-18:00",
},
{
_id: "my-digital-sale-trigger",
name: "Digital products discount",
},
],
};
},
});ECOM_DISCOUNTS_TRIGGER is singular — only one component of this type is allowed per app. Do not scaffold or include two Discount Triggers service plugins in the same app.
customTriggerId in getEligibleTriggers must match an _id from listTriggersgetEligibleTriggers and listTriggersgetEligibleTriggers is called during checkout to determine which triggers are currently activelistTriggers provides the master list of all possible triggers for configuration in the Wix dashboard