I would like to add an automation, that allows me, when triggered, that a person automatically gets added to s specific online program.
The scenario would be: a person buys a product in the store and with that purchase an online course (which is usually paid) is included for free. So the person should be added automatically to that program by automation.
At the moment I only see the option to “remove” participant" in the automations. Will this be possible with the NEW automation builder? Maybe it can be solved by a workaround with a Velo Code ?
Thanks!!
To automate adding a user to an online course when they purchase a specific product in your Wix store, follow these steps:
Steps to Set Up Automation
Set Up Course Program: Ensure your online course is configured in Wix and note its ID.
Create an Automation Trigger:
In Wix Automations, create a new automation with the trigger “When a product is purchased.”
Implement Velo Code:
Since direct actions to add participants may not be available, use Velo to create a backend function:
// In your backend code
import wixStores from 'wix-stores';
export function onProductPurchased(orderId) {
return wixStores.getOrder(orderId)
.then(order => {
const userId = order.customerId;
const productId = "YOUR_PRODUCT_ID";
if (order.lineItems.some(item => item.productId === productId)) {
// Add logic to enroll user in the course here
}
})
.catch(error => console.error("Error processing order: ", error));
}
Trigger the Function: Set up a webhook or event that triggers onProductPurchased when an order is completed.
Test the Automation: Make a test purchase to verify that the user is added to the course.
Note
Ensure the addToCourse logic is implemented according to your course setup. If you need further assistance, check the Wix Velo documentation. Let me know if you have more questions or need assistance!