Hi all
I would like to loop through the current member’s orders, and once a condition is found, break the loop, but this is the first time I have tried a loop on my Wix site and I am having problems getting it to work. I have included my code below. Is there anything obvious that I am missing?
The error in the console log states “Uncaught (in promise) TypeError: Cannot read property ‘length’ of undefined”, but I suspect this isn’t the only issue and I am struggling to find resources to help fix it.
import wixPaidPlans from 'wix-paid-plans';
const planName = "TEST";
const options = {
day: "numeric",
month: "short",
year: "numeric"
};
let orderId;
let validUntil;
let today = new Date()
let price;
$w.onReady(function () {
wixPaidPlans.getCurrentMemberOrders()
.then((orders) => {
for (let i = 0; i < orders.items.length; i++) {
if (orders.items[i].planName === planName && orders.items[i].status === "ACTIVE") {
$w('#text35').text = "paid member on recurring";
break;
} else {
if (orders.items[i].planName === planName && orders.items[i].validUntil >= today) {
$w('#text35').text = "cancelled member still within expiry";
break;
} else {
$w('#text35').text = "standard member";
break;
}
}
}
})
});