wixLocation.to code not working

Need help!! I have a page where the user chooses a plan and is redirected to a page. The code for chosing the plan and redirecting is working fine when i separate in 2 buttons, but when i put both codes together the link to the other page doesn’t work.

My code bellow:
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
import wixPaidPlans from ‘wix-paid-plans’;
import wixPay from ‘wix-paid-plans’;
let planId = “7833a4b0-c2b2-4418-9e9f-7a271cc44bf0”
let planId2 = “6307302e-9ec3-4b0d-8091-fb95451c657c”

$w.onReady( function () {
} );

export function buttonConsultorClick(event, $w) {
wixPaidPlans.purchasePlan(planId2) / /this function works well
.then( (myPurchase) => {
let myOrderId = myPurchase.orderId;
let myWixPayOrderId = myPurchase.wixPayOrderId;
let myWixPayStatus = myPurchase.wixPayStatus;
} );
wixLocation.to(“https://www.apessoacerta.com/consultorform1”) //This is the part that doesn’t work
}
export function button3_click(event, $w) { //this function works well when separated
wixLocation.to(“https://www.apessoacerta.com/consultorform1”);
}

Thank you,

Move it into the “then()” part of the promise.

Thanks JD. I just did. Still not working :frowning:

export function buttonConsultorClick(event, $w) {
wixPaidPlans.purchasePlan(planId2)
.then( (myPurchase) => {
let myOrderId = myPurchase.orderId;
let myWixPayOrderId = myPurchase.wixPayOrderId;
let myWixPayStatus = myPurchase.wixPayStatus;
wixLocation.to(“https://www.apessoacerta.com/consultorform1”)
} );
}

@rickusp try:

export function buttonConsultor_click(event) {

And make sure it’s ticked on the property id.

@jonatandor35 thanks a lot for your support. But I still have the same issue: the plan part works fine but the link doesn’t

export function buttonConsultor_click(event) {
wixPaidPlans.purchasePlan(planId2)
.then( (myPurchase) => {
let myOrderId = myPurchase.orderId;
let myWixPayOrderId = myPurchase.wixPayOrderId;
let myWixPayStatus = myPurchase.wixPayStatus;
wixLocation.to(“https://www.apessoacerta.com/consultorform1”)
} );
}

I am guessing that the problem is that since takes a little time for the purchase to be effective the page is not loading. Is there a way to ask the wix.location.to function to wait for the previous function to be loaded. Or to effect the plan purchase just after the new page is loaded?