Event Listener to trigger Javascript on certain button clicks
Budget: £20 – £250 GBP
I have a piece of javascript that disables the "NEXT" button on a checkout process on Wordpress using Bookly Pro, if the customer doesn't have all 5 products in their basket. (i.e we're selling "sessions" and if they have session 1, session 2, session 3 and session 4 in their basket the "NEXT" button remains disabled so they have to click "Continue shopping" until they have all 5 sessions...then the "NEXT" button is enabled.
here's the code:
const sessions = ['session 1', 'session 2', 'session 3']
const searchTarget = document.querySelector('.bookly-cart-step');
const submitButton = document.querySelector('.bookly-next-step')
if (searchTarget.textContent.includes('session')) {
if (!sessions.every((session) => searchTarget.textContent.includes(session))) {
submitButton.setAttribute("disabled", "")
} else {
submitButton.removeAttribute('disabled')
}
};
The help I need, is that I need the javascript to trigger each time the customer reaches the Basket stage of the checkout. So I understand I need assistance with an Event listener that can make it trigger at the right point of the checkout process, every time they return to the basket,
here's the code:
const sessions = ['session 1', 'session 2', 'session 3']
const searchTarget = document.querySelector('.bookly-cart-step');
const submitButton = document.querySelector('.bookly-next-step')
if (searchTarget.textContent.includes('session')) {
if (!sessions.every((session) => searchTarget.textContent.includes(session))) {
submitButton.setAttribute("disabled", "")
} else {
submitButton.removeAttribute('disabled')
}
};
The help I need, is that I need the javascript to trigger each time the customer reaches the Basket stage of the checkout. So I understand I need assistance with an Event listener that can make it trigger at the right point of the checkout process, every time they return to the basket,