Custom Action
Use WPLoyalty's Custom Action to reward customers for specific actions with flexible, personalized campaigns.
Last updated
Was this helpful?
Use WPLoyalty's Custom Action to reward customers for specific actions with flexible, personalized campaigns.
Last updated
Was this helpful?
The Custom Action feature in WPLoyalty provides an additional method for store owners to award loyalty points to customers for specific actions. This functionality is especially beneficial for campaigns like Achievement Campaigns, where users can earn points by reaching milestones such as Daily Sign-In or Moving Up a Level. The Custom Action mechanism allows for greater flexibility, enabling points and rewards to be triggered by custom events like form submissions or other user-specific actions.
This feature can be extended to a limitless number of custom triggers, provided the necessary conditions are met, such as the inclusion of a user_email parameter in the action or filter. In this documentation, we will guide you through setting up Custom Actions in WPLoyalty using an example of integrating it with Elementor Forms.
The Custom Action functionality in WPLoyalty allows you to customize how and when your customers earn loyalty points beyond predefined actions such as sign-ins or purchases. By implementing custom hooks, store owners can trigger actions such as earning loyalty points when users perform specific tasks on the website, such as submitting a form or interacting with other third-party integrations.
Requirements
To successfully set up a custom action:
The action or filter you want to trigger must include user_email as a parameter. This ensures that the custom action can be executed for the correct user.
Store owners should have basic knowledge of WordPress actions and filters to trigger the custom logic.
In this section, we will walk through an example where customers can earn points when submitting an Elementor Form. This will use the elementor_pro/forms/new_record hook to trigger the custom action. Kindly check with the
Scenario: Earn Points on Form Submission
Goal: Allow a customer to earn loyalty points when they submit a form, ensuring that they only earn once.
Step 1: Design the Form
Create the form in Elementor where customers can input their details (e.g., name, email, etc.).
Get the form name and the ID of the email field from the form settings.
Step 2: Create the Hook to Trigger the Custom Action
Create a hook that will trigger the custom action when a user submits the form.
Explanation:
We first check if the submitted form is the one we created by verifying the form name.
Next, we retrieve the email field from the form using the field ID.
Once we obtain the email, we trigger a custom action (custom_newsletter_submitted) with the email as a parameter.
Step 3: Trigger the Custom Action
Now, trigger the Custom Action with the email parameter:
Explanation:
We construct the action data using the email in the user_email field.
The achievement_type is set to custom_action.
We define which campaigns the user can earn from by setting the allowed_campaign_ids parameter.
The applyEarnCustomAction method is called to apply the points.
Step 4: Validate Before Processing the Earnings
We will now validate the custom action before it is processed using the wlr_achievement_check_status hook.
Explanation:
First, we validate that the campaign_id matches the allowed campaigns.
Next, we query the EarnCampaignTransactions model to check if the user has already earned from this campaign.
If a transaction exists, we prevent the earning, otherwise, we allow the earning.
Bonus Tip: Customizing the Earning Logic
You can further customize the earning logic by interacting with the EarnCampaignTransactions object:
You can loop through past transactions to limit the number of times a user can earn for a particular action.
Modify the logic to meet specific business needs, like awarding points based on the number of actions performed.
The Custom Action functionality in WPLoyalty is highly customizable to fit any business requirements, and you can tailor the logic to suit your needs, whether you're allowing one-time earnings or setting limits based on user behavior.
By following this guide, you can integrate custom actions into your WPLoyalty campaigns, offering customers more ways to earn points and rewards based on their interactions with your site.
Next Steps:
You may also want to check out these helpful guides:
Still Unclear ?
For reference, watch the video tutorial: [].
If you need any assistance, please create a at our ticket system. We are always happy to assist you :)