How To Hide Add To Cart Button On Shopify - 2021 – EcomExperts
Shopify Blog

How To Hide Add To Cart Button On Shopify - 2021

Andrew Durot
8 min read

There are certain situations where you might want to hide the add to cart button on your Shopify store. For instance, if you’re trying to keep customers from buying a product not available for sale or if the item is made to order and you don’t want the button to be shown to anyone who already ordered it. 


Depending on your needs, you can choose to hide the add to cart button on any product page. In this article, you’ll find a step-by-step instruction for you to hide the add to cart button on your Shopify store using code. 


Create a new product template


To replace the Add to cart button for a product, you will need to create a custom product template for that product.

      

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Templates directory, click Add a new template.
  4. Create the product template:
    1. From the drop-down menu, select product.
    2. Name your template requires-contact
    3. Click Create template.
  5. Find the following code:

 {% section 'product-template' %}

  1. Replace it with:

{% section 'product-template-requires-contact' %}

  1.  This code links your new template with a new product section that you will create in the next steps.
  2. Click Save.

Create a new product section

  1. In the Sections directory, click Add a new section.
  2. Create the section:
  1. Name your new section product-template-requires-contact
  2. Click Create section.
  1. Delete all of the default code in the section file, so that the file is empty.
  2. In the Sections directory, click product-template.liquid. Copy all the content of the file to your clipboard.
  3. Return to your new product-template-requires-contact.liquid section, and paste the code into the file.
  4. Click Save.

 

Hide the Add to cart button

  • In your new product-template-requires-contact.liquid section file, find the HTML code for the Add to cart button of your product page. You can find it by searching for the word cart in the file.
  • The code for the Add to cart button varies from theme to theme. Look for an <input> or <button> tag with text like Add to cart, AddToCart, or add-to-cart.
  • For Debut, the Add to cart button code looks like this:
  •  

    <button type="submit" name="add" id="AddToCart-{{ section.id }}" {% unless current_variant.available %}disabled="disabled"{% endunless %} class="btn product-form__cart-submit{% if product.options.size == 1 and product.variants[0].title == 'Default Title' %} product-form__cart-submit--small{% endif %}">  <span id="AddToCartText-{{ section.id }}">    {% unless current_variant.available %}      {{ 'products.product.sold_out' | t }}    {% else %}      {{ 'products.product.add_to_cart' | t }}    {% endunless %}  </span></button>

  • When you find the code, wrap it in Liquid {% comment %} and {% endcomment %} tags. This will stop the code from being shown on your store, but will let you easily put it back if you want to change your new template later.
  • For Debut, the modified code would look like this:

  •     {% comment %}    <button type="submit" name="add" id="AddToCart-{{ section.id }}" {% unless current_variant.available %}disabled="disabled"{% endunless %} class="btn product-form__cart-submit{% if product.options.size == 1 and product.variants[0].title == 'Default Title' %} product-form__cart-submit--small{% endif %}">      <span id="AddToCartText-{{ section.id }}">        {% unless current_variant.available %}          {{ 'products.product.sold_out' | t }}        {% else %}          {{ 'products.product.add_to_cart' | t }}        {% endunless %}      </span>    </button>    {% endcomment %}

  • Caution: Make sure that you don't comment out the <form> tags for your product page. Your comment tags should not surround any <form> or </form> tags, otherwise customers might experience errors when viewing your product page.

  • In case your theme has a Buy it now button, you will need to also wrap that in the  {% comment %} and {% endcomment %}
  • Click Save.

  • Add an email link or contact form

    Now that you have hidden the Add to cart button, you can add the content you want to show instead.


    Email link

    You can add an email link that will open the customer's default email program and enter your store's customer-facing email address as the recipient. To add an email link:

    1. On a new line below the Liquid {% endcomment %} tag that you added in the last step, add the HTML code for an email link:

        <p>Please <a href="mailto:{{ shop.email }}">contact us</a> if you are interested in this product.</p>

    1. Click Save.

    Contact form

    You can add a contact form to your new product template by copying the code from your theme's contact page template. To add a contact form:

    1. In the Templates directory, click page.contact.liquid.
    2. Find the Liquid {% form 'contact' %} tag in the file.
    3. Copy all of the code from the Liquid {% form 'contact' %} tag down to the Liquid {% endform %} tag. Include the Liquid form tags in the code that you copy.
    4. Return to your new product-template-requires-contact.liquid file in the Sections directory.
    5. Find the closing </form> tag in the file. On a new line below the closing </form> tag, paste the code for the contact form.
    6. The next step is to wrap the code that you just pasted in HTML div tags. The class attribute included in the div tag code will ensure that your contact form renders correctly on the page.
    7. On a new line above {% form 'contact' %}, paste the following code:

    <div class="form-vertical"></div>

    1. On a new line below {% endform %}, paste the following code:

      </div>
    2. In case you don't have {% form 'contact' %} paste the following code on a new line below the Liquid {% endcomment %} tag that you added in the last step:

        <div class="contact-form form-vertical">

            {%- assign formId = 'ContactForm' -%}

            {% form 'contact', id: formId %}

              {% include 'form-status', form: form, form_id: formId %}

     

              <div class="grid grid--half-gutters">

                <div class="grid__item medium-up--one-half">

                  <label for="{{ formId }}-name">{{ 'contact.form.name' | t }}</label>

                  <input type="text" id="{{ formId }}-name" name="contact[{{ 'contact.form.name' | t }}]" value="{% if form[name] %}{{ form[name] }}{% elsif customer %}{{ customer.name }}{% endif %}">

                </div>

                <div class="grid__item medium-up--one-half">

                  <label for="{{ formId }}-email">{{ 'contact.form.email' | t }} <span aria-hidden="true">*</span></label>

                  <input

                    type="email"

                    id="{{ formId }}-email"

                    name="contact[email]"

                    autocorrect="off"

                    autocapitalize="off"

                    value="{% if form.email %}{{ form.email }}{% elsif customer %}{{ customer.email }}{% endif %}"

                    aria-required="true"

                    {%- if form.errors contains 'email' -%}

                      class="input--error"

                      aria-invalid="true"

                      aria-describedby="{{ formId }}-email-error"

                    {%- endif -%}

                    >

                  {%- if form.errors contains 'email' -%}

                    <span id="{{ formId}}-email-error" class="input-error-message">

                      <span class="visually-hidden">{{ 'general.accessibility.error' | t }} </span>

                      {% include 'icon-error' %}

                      <span>{{ form.errors.translated_fields['email'] | capitalize }} {{ form.errors.messages['email'] }}.</span>

                    </span>

                  {%- endif -%}

                </div>

              </div>

     

     

              <label for="{{ formId }}-message">{{ 'contact.form.message' | t }}</label>

              <textarea rows="10" id="{{ formId }}-message" name="contact[{{ 'contact.form.message' | t }}]">{% if form.body %}{{ form.body }}{% endif %}</textarea>

     

              <input type="submit" class="btn" value="{{ 'contact.form.submit' | t }}">

     

            {% endform %}

          </div>


    1. Click on Save

    Assign your new template to a product

    Now that the template is finished, you can assign it to all of the products for which you want to hide the Add to cart button.

    1. From your Shopify admin, go to Products > All products.
    2. Click the name of a product that you want to hide the Add to cart button on.
    3. On the product page of your Shopify admin, under Theme templates, choose your new requires-contact template from the Template suffix drop-down.
    4. Click Save.

    Repeat these steps for each product to which you want to add your new template.

    Hiding the add to cart button on your Shopify store would go seamlessly if you follow this guide and use the code included. By doing this, you’ll create a more seamless shopping experience for your customers. 

    Leave a comment

    Guides

    Leave a comment