I am using the Pricing & Plans app from Wix. I need to redirect my users to a specific page after they purchase their plan, not the home page. I created a backend file called events.jsw and the code I wrote there is this:
import wixData from 'wix-data';
import wixLocation from 'wix-location';
export function wixPaidPlans_onPlanPurchased(event) {
wixLocation.to("the page i want to redirect to");
}
I also put similar code on the actual pricing and plans page:
import wixEventsBackend from 'wix-events-backend';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
export function wixPaidPlans_onPlanPurchased(event) {
wixLocation.to("the page i want to redirect to");
}
This method does not work and I can't seem to figure out what other code options there are in the API. Appreciate all the help!
Also, please go and do the Feature Request for this. It is a nonsense experience for this app to not to allow the redirect customization by default.
Copying the code I used on one of my sites. You need to add the event handler to the backend as well. Naturally you'll need to change the planIDs and page urls plus the image (#group4) that shows during the plan purchase confirmation.
This works but the same code does not work on another site. Maybe @Yisrael (Wix) might give us some insight.
// API Reference: https://www.wix.com/velo/reference/api-overview/introduction // “Hello, World!” Example: https://learn-code.wix.com/en/article/1-hello-world import wixLocation from 'wix-location'; import wixData from 'wix-data'; import wixUsers from 'wix-users'; function getUTCTime() { var utcTime = new Date() utcTime.setMinutes(utcTime.getMinutes() + utcTime.getTimezoneOffset()) console.log(utcTime) return utcTime } $w.onReady(async function () { let date = new Date() console.log(date) let newDate = date.setMinutes(date.getMinutes() - 1); console.log(date) wixLocation.onChange(async (location) => { let newPath = location.path; if (newPath.includes("status")) { // wixLocation.to("/paid-plan-purchase"); $w('#group4').show() $w('#membershipPlanPickerTpa1').hide() let user = wixUsers.currentUser; let userId = user.id; await wait(4000); let date = await getUTCTime() console.log(date) let newDate = date.setMinutes(date.getMinutes() - 1); console.log(date) wixData.query("PaidPlanPurchases") .eq("paymentStatus", "PAID") .eq("memberId", userId) //.ge("_createdDate", newDate) .find() .then((results) => { if (results.items.length > 0) { console.log("Found") let firstItem = results.items[0]; console.log(firstItem) let plan = firstItem.planID if (plan === "41e4fcbc-9ef9-4a21-adf9-46c5913638a9") { wixLocation.to("https://www.mattsoule.com/account/free-membership"); } else if (plan === "bfea41d3-a4bf-4f19-aec6-95346d3830fb") { wixLocation.to("https://www.mattsoule.com/account/master-stress-membership"); } } else { console.log("NotFound") $w('#group4').hide() $w('#membershipPlanPickerTpa1').show() // $w('#text108').show() // $w('#button1').show() } }) .catch((err) => { let errorMsg = err; }); } }); }); function wait(ms = 500) { return new Promise((res) => { setTimeout(() => { res("done") }, ms); }); }
===Backend js.===
import wixData from 'wix-data'; export function wixPaidPlans_onPlanPurchased(event) { console.log("Triggered") console.log(event) let plan = event.order.planId let toInsert = { "planID": event.order.planId, "memberId": event.order.memberId, "paymentStatus": event.order.paymentStatus, }; wixData.insert("PaidPlanPurchases", toInsert) .then((results) => { let item = results; console.log(item) console.log("Inserted to Database") }) .catch((err) => { let errorMsg = err; console.log("Error Inserted to Database") console.log(errorMsg) }); } export function test() { var utcTime = new Date() utcTime.setMinutes(utcTime.getMinutes() + utcTime.getTimezoneOffset()) console.log(utcTime) return utcTime }
Same problem
@pm325 Been complaining about this for a while myself. It has to be a default feature like you mentioned.
Haven't figured it out and this is such a huge oversight from Wix. This should be an obvious feature of the app by default.
Anyone figured this out yet - such an awful success message that comes up at the moment! Also need to change the message re subscribing to access a page that only has permissions for members that have paid for a certain plan.