Hello Guys, I would like to send a triggered email after plan purchase, right now all my customers receive the same email, but I want them to receive specific emails depending on the plan they purchase.
This is the code I have now to allow them to purchase a specific plan
import wixWindow from 'wix-window';
import wixPaidPlans from 'wix-paid-plans';
import wixPay from 'wix-pay';
import wixUsers from 'wix-users';
$w.onReady(function () {
let planId = 'PLAN ID'; // Get the plan ID for a free plan
$w('#buyNow').onClick((event) => {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
if (!isLoggedIn) {
wixUsers.promptLogin().then(() => {
processPlan(planId);
})
} else {
processPlan(planId);
}
});
});
function processPlan(myId) {
wixPaidPlans.purchasePlan(myId)
.then( (myPurchase) => {
let myOrderId = myPurchase.orderId;
} );
}
Reading about the Emailuser function I saw this code:
import wixUsers from 'wix-users';
2
3// ...
4
5let userId = wixUsers.currentUser.id;
6
7wixUsers.emailUser("emailID", userId)
8 .then( () => {
9 console.log("Triggered email sent");
10 } )
11 .catch( (err) => {
12 console.log(err);
13 } );
But I don’t know exactly how to make them work together, so they will receive the email after the purchase and not when they press the buy button.
Hope you guys can help me with this little task! Thank you in advance.
PS: Just in case is easier for me to understand later. I am going to put here the code I got after creating the Triggered email in case whoever helps me wanted to use it.
import wixUsers from 'wix-users';
//...
wixUsers.emailUser('SBSrA3j', <enter-user-id-here>);