FROM CACHE - en_header

Forms - Add a back in stock notification form

TyW
Community Manager
Community Manager
416 40 1107

With a back in stock notification form, customers can let you know if they want to be informed when a sold out product becomes available again. When a customer uses the form to submit their email address, you will be sent information about the product that they are interested in. When more stock becomes available, you can let the customer know.

 

stock01.jpg

 

Note: If a product has variants, then each variant must be sold out for the form to appear on the product page. To use a form that appears for sold out variants, even when other variants for the same product are available, you will need to install a free or paid back in stock app from the Shopify App Store.

 

 

Sectioned and non-sectioned themes

 

 

The steps for this tutorial differ depending on whether you are using a sectioned or a non-sectioned theme. A sectioned theme is a newer theme that lets you drag and drop to arrange the layout of your store's pages.

 

To figure out whether your theme supports sections, go to the theme's Edit code page. If there are files in the Sections directory, you are using a sectioned theme. Non-sectioned themes were released before October 2016, and do not have files in the Sections directory.

 

If you are using a sectioned theme, then click the Sectioned themes link and follow the instructions. If you are using an older, non-sectioned theme, then click the Non-sectioned themes link and follow the instructions.

 

TyW | Online Community Manager @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Replies 39 (39)
relledge98
New Member
9 0 0

I am using Testament theme and unable to find code in product-template.liquid any advice?

Quondy
Explorer
72 0 20

Hello @TyW ,

 

I have tried to follow up the instructions of the tutorial but I am stuck at the first instruction. I have been trying to find the HTML but it does not work for the Debut theme. I have installed Debut theme in March 2020.

 

Please, since there are other users with my same problem, can you please share an updated version of the "Notify Me Form" that works with Liquid code?

 

Thank you

 

 

mctenold
Shopify Partner
47 0 6

For clarity everyone, this just basically adds a contact form to the product page if the product is out of stock. This does NOT send any automatic notification emails to the customer once an item is back in stock.

shoptstarrbouti
New Member
3 0 0

Hi , the instructions were not clear. Can you assist me with this please ? 

shoptstarrbouti
New Member
3 0 0

Hi , the instructions were not clear. Can you assist me with this please ? 

thewoobles
New Member
4 0 0

I put the if / end if around this part of my Debut Shopify code and it worked:

{% if product.available %}

{% capture "form_classes" -%}
product-form product-form-{{ section.id }}
{%- unless section.settings.show_variant_labels %} product-form--hide-variant-labels {% endunless %}
{%- if section.settings.enable_payment_button and product.has_only_default_variant %} product-form--payment-button-no-variants {%- endif -%}
{%- if current_variant.available == false %} product-form--variant-sold-out {%- endif -%}
{%- endcapture %}


{% form 'product', product, class:form_classes, novalidate: 'novalidate', data-product-form: '' %}
{% unless product.has_only_default_variant %}
<div class="product-form__controls-group">
{% for option in product.options_with_values %}
<div class="selector-wrapper js product-form__item">
<label {% if option.name == 'default' %}class="label--hidden" {% endif %}for="SingleOptionSelector-{{ forloop.index0 }}">
{{ option.name }}
</label>
<select class="single-option-selector single-option-selector-{{ section.id }} product-form__input"
id="SingleOptionSelector-{{ forloop.index0 }}"
data-index="option{{ forloop.index }}"
>
{% for value in option.values %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{% endfor %}
</select>
</div>
{% endfor %}
</div>
{% endunless %}


<select name="id" id="ProductSelect-{{ section.id }}" class="product-form__variants no-js">
{% for variant in product.variants %}
<option value="{{ variant.id }}"
{%- if variant == current_variant %} selected="selected" {%- endif -%}
>
{{ variant.title }} {%- if variant.available == false %} - {{ 'products.product.sold_out' | t }}{% endif %}
</option>
{% endfor %}
</select>

{% if section.settings.show_quantity_selector %}
<div class="product-form__controls-group">
<div class="product-form__item">
<label for="Quantity-{{ section.id }}">{{ 'products.product.quantity' | t }}</label>
<input type="number" id="Quantity-{{ section.id }}"
name="quantity" value="1" min="1" pattern="[0-9]*"
class="product-form__input product-form__input--quantity" data-quantity-input
>
</div>
</div>
{% endif %}

<div class="product-form__error-message-wrapper product-form__error-message-wrapper--hidden{% if section.settings.enable_payment_button %} product-form__error-message-wrapper--has-payment-button{% endif %}"
data-error-message-wrapper
role="alert"
>
<span class="visually-hidden">{{ 'general.accessibility.error' | t }} </span>
{% include 'icon-error' %}
<span class="product-form__error-message" data-error-message>{{ 'products.product.quantity_minimum_message' | t }}</span>
</div>

<div class="product-form__controls-group product-form__controls-group--submit">
<div class="product-form__item product-form__item--submit
{%- if section.settings.enable_payment_button %} product-form__item--payment-button {%- endif -%}
{%- if product.has_only_default_variant %} product-form__item--no-variants {%- endif -%}"
>
<button type="submit" name="add"
{% unless current_variant.available %} aria-disabled="true"{% endunless %}
aria-label="{% unless current_variant.available %}{{ 'products.product.sold_out' | t }}{% else %}{{ 'products.product.add_to_cart' | t }}{% endunless %}"
class="btn product-form__cart-submit{% if section.settings.enable_payment_button %} btn--secondary-accent{% endif %}"
{% if settings.enable_ajax %}aria-haspopup="dialog"{% endif %}
data-add-to-cart>
<span data-add-to-cart-text>
{% unless current_variant.available %}
{{ 'products.product.sold_out' | t }}
{% else %}
{{ 'products.product.add_to_cart' | t }}
{% endunless %}
</span>
<span class="hide" data-loader>
{% include 'icon-spinner' %}
</span>
</button>
{% if section.settings.enable_payment_button %}
{{ form | payment_button }}
{% endif %}
</div>
</div>
{% endform %}
</div>

{% endif %}

thewoobles
New Member
4 0 0

I have multiple items that are out of stock. Is there a way to modify the automatically generated email so that I know which item the customer signed up for a notification for?

charu_15
New Member
1 0 0

It is working but I am not receiving any emails from Shopify when the product is in stock.

lynda
New Member
2 0 0

Your code worked great for me. Thank you so much for sharing!!! I got the text to appear "Click here to be notified..." but not the email form. Any advice would be greatly appreciated.

StudioSicily
Tourist
3 0 1

Same problem here, could anyone help?

Racheal2021
New Member
2 0 2

what you have just described does not exist in that template im afraid but thanks

FelipePartnerBR
New Member
5 0 0

 

Click to expand...
Correction - Code positioning

Hi! 

 

Seems like I know what you are missing here.

The <form being mentioned is actually written differently.

The code for the product form you are looking for is at Sections > product-template.liquid (around line 130):

{% capture "form_classes" -%}
product-form product-form-{{ section.id }}{% unless section.settings.show_variant_labels %} product-form--hide-variant-labels{% endunless %}{% if section.settings.enable_payment_button and product.has_only_default_variant%} product-form--payment-button-no-variants{% endif %}
{%- endcapture %}


So you should wrap the code above with {% if product.available %} at the top and {% endif %} at the bottom.

Final result should be:

{% if product.available %}
{% capture "form_classes" -%}
product-form product-form-{{ section.id }}{% unless section.settings.show_variant_labels %} product-form--hide-variant-labels{% endunless %}{% if section.settings.enable_payment_button and product.has_only_default_variant%} product-form--payment-button-no-variants{% endif %}
{%- endcapture %}
{% endif %}

 

After this, save your file. Now, copy the following code:

{% unless product.available %}
<div id="sold-out">
  {% form 'contact' %}
    {% if form.posted_successfully? %}
    <p class="accent-text">Thanks! We will notify you when this product becomes available!</p>
    {% else %}
    <p>Click <a id="notify-me" href="#"><strong>here</strong></a> to be notified by email when {{ product.title }} becomes available.</p>
    {% endif %}
    {% if form.errors %}
    <div class="error feedback accent-text">
      <p>Please provide a valid email address.</p>
    </div>
    {% endif %}
    {% unless form.posted_successfully? %}
    <div id="notify-me-wrapper" class="clearfix" style="display:none">
      {% if customer %}
      <input type="hidden" name="contact[email]" value="{{ customer.email }}" />
      {% else %}
      <input style="float:left; width:180px;" required="required" type="email" name="contact[email]" placeholder="your@email.com" class="styled-input{% if form.errors contains 'email' %} error{% endif %}" value="{{ contact.fields.email }}" />
      {% endif %}
      <input type="hidden" name="contact[body]" value="Please notify me when {{ product.title | escape }} becomes available." />
      <input style="float:left; margin-left:5px;" class="btn styled-submit" type="submit" value="Send" />
    </div>
    {% endunless %}
  {% endform %}
</div>
{% endunless %}

 

Paste it into to the same file (product-template.liquid) where it fits you the most. I personally prefer it below the Add to Cart button. Look for the payment button code and paste it right below the closing /div.

The payment button code should look like this - around line 180:

<div class="product-form__item product-form__item--submit{% if section.settings.enable_payment_button %} product-form__item--payment-button{% endif %}{% if product.has_only_default_variant %} product-form__item--no-variants{% endif %}">
<button type="submit" name="add"
{% unless current_variant.available %} aria-disabled="true"{% endunless %}
aria-label="{% unless current_variant.available %}{{ 'products.product.sold_out' | t }}{% else %}{{ 'products.product.add_to_cart' | t }}{% endunless %}"
class="btn product-form__cart-submit{% if section.settings.enable_payment_button %} btn--secondary-accent{% endif %}"
data-add-to-cart>
<span data-add-to-cart-text>
{% unless current_variant.available %}
{{ 'products.product.sold_out' | t }}
{% else %}
{{ 'products.product.add_to_cart' | t }}
{% endunless %}
</span>
<span class="hide" data-loader>
{% include 'icon-spinner' %}
</span>
</button>
{% if section.settings.enable_payment_button %}
{{ form | payment_button }}
{% endif %}
</div>
{% endform %}
</div>

Insert the code right after this and you should be fine.

Hope you can make it, hit me up if you need something else.

juicer
New Member
6 0 0

This solution works perfect but I just have 1 issue left. For some reason, the zoom function on my featured images doesn't work anymore and I cannot swap to look at other photos. Instead, the photos open up in a new tab?!

tristancliffe2
New Member
2 0 0

I can't get this to work.

I am using the default Debut theme.

I have pasted the code into product-template.liquid, and the jQuery into theme.js. I can see the "Click here to be notified..." text, but clicking here doesn't actually do anything - no fade in of an email box. The browser status bar says https://xxxx.myshopify.com/products/air-cleaner-baffle# 

The page looks how I want it to, it's just that the click here bit doesn't produce a form...

My code (copied and pasted from previous posts)

jQuery('#notify-me').click(function() {

jQuery('#notify-me-wrapper').fadeIn();

return false;
} );

 

 {% unless product.available %}
			<div id="sold-out">
  {% form 'contact' %}
    {% if form.posted_successfully? %}
    <p class="accent-text">Thanks! We will notify you when this product becomes available!</p>
    {% else %}
    <p>Click <a id="notify-me" href="#"><strong>here</strong></a> to be notified by email when {{ product.title }} becomes available.</p>
    {% endif %}
    {% if form.errors %}
    <div class="error feedback accent-text">
      <p>Please provide a valid email address.</p>
    </div>
    {% endif %}
    {% unless form.posted_successfully? %}
    <div id="notify-me-wrapper" class="clearfix" style="display:none">
      {% if customer %}
      <input type="email" name="contact[email]" value="{{ customer.email }}" />
      {% else %}
      <input style="float:left; width:180px;" required="required" type="email" name="contact[email]" placeholder="your@email.com" class="styled-input{% if form.errors contains 'email' %} error{% endif %}" value="{{ contact.fields.email }}" />
      {% endif %}
      <input type="hidden" name="contact[body]" value="Please notify me when {{ product.title | escape }} becomes available." />
      <input style="float:left; margin-left:5px;" class="btn styled-submit" type="submit" value="Send" />
    </div>
    {% endunless %}
  {% endform %}
</div>
{% endunless %}

 

What have I done wrong?

tristancliffe
Tourist
15 0 1

Hello. I can't get this to work on my test (private) shop.

Running default Debut theme.

I have added the following to product.template.liquid:

{% unless product.available %}
			<div id="sold-out">
  {% form 'contact' %}
    {% if form.posted_successfully? %}
    <p class="accent-text">Thanks! We will notify you when this product becomes available!</p>
    {% else %}
    <p>Click <a id="notify-me" href="#"><strong>here</strong></a> to be notified by email when {{ product.title }} becomes available.</p>
    {% endif %}
    {% if form.errors %}
    <div class="error feedback accent-text">
      <p>Please provide a valid email address.</p>
    </div>
    {% endif %}
    {% unless form.posted_successfully? %}
    <div id="notify-me-wrapper" class="clearfix" style="display:none">
      {% if customer %}
      <input type="email" name="contact[email]" value="{{ customer.email }}" />
      {% else %}
      <input style="float:left; width:180px;" required="required" type="email" name="contact[email]" placeholder="your@email.com" class="styled-input{% if form.errors contains 'email' %} error{% endif %}" value="{{ contact.fields.email }}" />
      {% endif %}
      <input type="hidden" name="contact[body]" value="Please notify me when {{ product.title | escape }} becomes available." />
      <input style="float:left; margin-left:5px;" class="btn styled-submit" type="submit" value="Send" />
    </div>
    {% endunless %}
  {% endform %}
</div>
{% endunless %}

And the following to theme.js:

jQuery('#notify-me').click(function() {

jQuery('#notify-me-wrapper').fadeIn();

return false;
} );

 

I am happy with the layout without the {% if product.available %} on either side of the form further up, so I have omitted that, but even if I try it nothing works.

Any ideas?

grandpoke29
New Member
1 0 0

Great code and tutorial, it worked perfectly on my end.

However, I have a noob question: Where actually stores the email and how can I access the list?

 

Thank you.

camillecee92
New Member
1 0 0

Hi! I can't find the <form> tag. Can someone please advise? Thx! 

rizaldy
Shopify Partner
9 0 1

Hi @TyW 

Thank you for sharing these codes! It works perfectly on my end. However, is there any way to email back the customers automatically when the products are back in stock?

AntoP
Tourist
7 0 2

Hi,

 

great advice it works!

However I've a small question: how can I specify a Subject line for the notification email?

All notifications come with a default "New customer message on..."

I'd like to use the subject line to organise my inbox.

 

Thanks!

webg1rl
Tourist
7 0 1

Hello, We have implemented this into the Debut theme, but we have a bit of a problem after the form is submitted. The page jumps down to the bottom of the page and does not stay in the location of the confirmation message so the visitor knows the email was submitted. Any help in keeping the form from scrolling down after submission would be much appreciated.