Skip to content

Back in stock plugin for Craft Commerce that notifies subscribed users via an automated email

License

Notifications You must be signed in to change notification settings

jmauzyk/craft-commerce-back-in-stock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Back In Stock plugin for Craft Commerce 2

Back In Stock plugin for Craft Commerce 4

This plugin allows anyone to register interest on out of stock products. If they do and the product becomes re-stocked an email will automatically be sent to all interested emails with a link prompting them to buy now.

The plugin comes with a basic, responsive email template but can be replaced with a custom template. The subject line of the email can also be customized via the plugins settings.

Installation

Either by the plugin store (search "Back In Stock") or via composer.

"mediabeastnz/craft-commerce-back-in-stock": "^2.0.0"

Requirements

This plugin requires Craft CMS 4.0.0 or later and Craft Commerce 4.0 or later.

Frontend form setup

This plugin allows you to send a form submission to specific action which will create the necessary records.

You will need to implement the logic that displays this form if a product is out of stock but I have created a helper template to help get you started.

Use something like hasStock to check if the product/variant is out of stock.

The form will need 3 fields. 2 hidden fields and 1 visible field where the user can enter their email.

<input type="hidden" name="action" value="craft-commerce-back-in-stock/base/register-interest">
<input type="hidden" name="variantId" value="{{ product.defaultVariant.id }}">
<input type="text" name="email" value="{{ currentUser.email }}">

The variantId fields value might need to be dynamic if your site allows the user to change variants e.g. select. I recommend a simple script to ensure the selected variant is populated here.

If you only have one variant then use the example provided above.

You can also include an options value to save additional information with the form submission. This should be in the form of a JSON object. This input is entirely optional.

{% set options = { title: 'Some Title', productAttribute: 'Some Value' } %}

<input type="hidden" name="options" value="{{ options | json_encode }}">

You can use these variables in your email template, or subject line via options.title (as per the above example). Make sure you check to see if values exist when doing so!

Check out the helper template (built using Tailwind) if you need some to get you started.

Automatically Purge Notification Requests

If privacy is a requirement you'll want to enable "Automatically Purge Notification Requests". This will delete the users information once they have been notified rather than being kept in the database.

Screenshot of form example

About

Back in stock plugin for Craft Commerce that notifies subscribed users via an automated email

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Twig 58.6%
  • PHP 41.4%