top of page
Back in Stock Notification for Site Members

Back in Stock Notification for Site Members

Allow site members to receive a notification when a product is back in stock

Intermediate.png

Advanced

3K

Published:

May 13, 2020

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

This example displays a few products that can be purchased using Wix Stores.


On a product page of an item that is out of stock a “Notify Me When in Stock” button will appear. After clicking the button the member will be subscribed to the item’s stock availability, so once it’s back in stock they will get an email notification. The member can cancel his subscription to the item’s stock availability by clicking the “Cancel Notification” button in the item’s product page.


Note that the member needs to be logged-in to the site in order to see these buttons.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It

Collections

 

For this example we created a collection called “Stock Wait List” that holds the user’s email and a reference to the wanted item from the Stores/Products collection (which is created automatically when Wix Stores is added).

 

Page Elements

 

In the product page we added the following page element:

 

  • Subscription button - the button is displayed when the user is logged-in and the item is out of stock. The button’s label is “Notify me When in Stock”, but if the user has already subscribed to the notification the label is changed to “Cancel Notification”.

 

Backend Code

 

  • Jobs.config - a scheduled job that runs once a day and calls the CheckProductAvailability function.

 

  • CheckProductAvailability.jsw - includes a function that goes over the “Stock Wait List” collection and checks for each subscription if the product if it’s back in stock. If it is back in stock it calls the sendMail function in email.jsw to send a mail notification to the subscriber, and removes the record from the collection.

 

  • Email.jsw - includes the sendMail function that sends the mail to the subscribed user using sendgrid node module. In order to send the mail the module gets the Sendgrid API key from Secrets Manager.

 

Frontend Code

 

  • NofityButtonUIHandler - decides if to show the subscription button and what label to put on the button.

 

  • setOnClickNotifyButton - adds or removes a row from the “Stock Wait List” collection when the button is clicked.

 

  • getProductObj - checks if the product is in stock and what is the product’s id.

 

  • getUserEmail - gets the user’s email address

 

  • wixLocation.onChange - inits the button and event handlers accordion to the current product page.

APIs We Used

Non-code example.

Non-code example.

Non-code example.

Non-code example.

Non-code example.

Related Articles

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Related Items

Related Items

Recommend products based on price, brand and more.

Intermediate.png

Intermediate

Back in Stock Notification for Site Contacts

Back in Stock Notification for Site Contacts

Allow site visitors to register and receive a notification when a product is back in stock

Intermediate.png

Advanced

Highest-Rated Products

Highest-Rated Products

Showcase your highest-rated products in their own gallery.

Intermediate.png

Advanced

Product Configurator

Product Configurator

Let customers create one-of-a-kind products.

Intermediate.png

Advanced

Anchor 2
bottom of page