How do I add Notification When Back In Stock to my website

I have followed the article and have all the correct code but it doesn’t work. Can anybody help me resolve this issue? My following code is below:

Product Page
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';

wixLocation.onChange((location) => {

$w.onReady(() => {

async function notificationInit() {
 const productObj = await getProductObj();
 const userEmail = await getUserEmail();
 const userNotifyObj = await getUserNotifyObj(userEmail, productObj.productId);

    $w('#notifyButton').onClick(async () => await setOnClickNotifyButton(productObj, userEmail));
    notifyButtonUIHandler(productObj, userNotifyObj.shouldNotifyUser);

async function getUserNotifyObj(userEmail, productId) {
 const { items } = await wixData.query('stockWaitList').eq('product', productId).eq('userEmail', userEmail).find();
 const shouldNotifyUser = items.length > 0;

 const shouldNotifyUserObj = { shouldNotifyUser };
 if (shouldNotifyUser) {
        shouldNotifyUserObj.itemId = items[0]._id;

 return shouldNotifyUserObj;

function notifyButtonUIHandler(productObj, shouldNotifyUser) {
    productObj.isInStock ? $w('#notifyButton').hide() : $w('#notifyButton').show();
    $w('#notifyButton').label = shouldNotifyUser ? 'Cancel Notification' : 'Notify Me When In Stock';

async function setOnClickNotifyButton(productObj, userEmail) {
    $w('#notifyButton').label = 'please wait...'
 const newNotifyUserObj = await getUserNotifyObj(userEmail, productObj.productId);
 const objToInsert = {
        userEmail: userEmail,
        product: productObj.productId,
    newNotifyUserObj.shouldNotifyUser ? await wixData.remove('stockWaitList', newNotifyUserObj.itemId) : await wixData.insert('stockWaitList', objToInsert);
    notifyButtonUIHandler(productObj, !newNotifyUserObj.shouldNotifyUser);

async function getProductObj() {
 const { inStock, _id } = await $w('#productPage').getProduct();
 const productObj = {
        isInStock: inStock,
        productId: _id,

 return productObj;

function getUserEmail() {
 const user = wixUsers.currentUser;
 return user.getEmail();

Here is the following article:

Haiden from Tech Budz
CEO of Tech Budz

Hello Haiden :raised_hand_with_fingers_splayed:

You already have an inventory collection, clone this collection and create a job scheduler to compare the original inventory collection with yours and update it when necessary, create a beforeUpdate Hook on your new inventory collection to check if the product was out of stock (0) before the update, and that the new inventory status is in stock , then query another database where users subscribed to be notified with the product/variant ID to notify them with an email that the product is in stock again.

Hope this helps~!