Retrieves eligible custom discount triggers based on the provided items. The retrieved custom triggers are based on your own business logic.
The getEligibleTriggers()
function determines whether a cart or checkout's items meet the conditions for a discount to apply to an item.
The function is automatically called by Wix eCommerce when actions are performed on the cart or checkout entities/pages. For example, when adding an item to the cart.
getEligibleTriggers()
When you add the Custom Discount Trigger plugin, a folder is automatically added to your site. Use the .js
file in the folder to write the code to retrieve custom triggers.
For more information on setting up your custom triggers, see Tutorial: Custom Discount Trigger Service Plugin.
function getEligibleTriggers(
options: Options,
context: Context,
): Promise<EligibleTriggers>;
Line items and triggers.
Metadata about the request.
export const getEligibleTriggers = (options) => {
const colors = options.lineItems.map(
(item) => item.catalogReference.options.options.Color,
);
let result;
if (colors.includes("Grey")) {
result = {
eligibleTriggers: [
{
customTriggerId: "1",
identifier: options.triggers[0].identifier,
},
],
};
} else {
result = {
eligibleTriggers: [],
};
}
return result;
};
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.