How to add "add to cart button" to featured collection

Solved

How to add "add to cart button" to featured collection

Skence
Explorer
52 0 14

Hello shopify community!

 

Currently I am working on setting up a store with the Impact theme but I would like to put a "add to cart" button next or below the pricing in a featured collection. This way people should be able to add to the cart without needing to go to the product page first.

 

Could you please tell me how can I do that?

 

This is an example:

 

Screen Shot 2024-04-20 at 5.46.33 PM.png

my store: https://skence.com/

Accepted Solution (1)

lunaworks
Shopify Partner
452 44 48

This is an accepted solution.

You need to find the featured collection liquid file and then the position where you want to add the add to cart button and do something like this 

{%- form 'product', product, class: 'form', novalidate: 'novalidate',
        data-type: 'add-to-cart-form'
      -%}
<input
          type="hidden"
          name="id"
          value="{{ product.selected_or_first_available_variant.id }}"
          {% if product.selected_or_first_available_variant.available == false or quantity_rule_soldout %}
            disabled
          {% endif %}
          class="product-variant-id"
        >
<button
            id="ProductSubmitButton-{{ section_id }}"
            type="submit"
            name="add"
            class="product-form__submit button button--full-width {% if show_dynamic_checkout %}button--secondary{% else %}button--primary{% endif %}"
            {% if product.selected_or_first_available_variant.available == false or quantity_rule_soldout %}
              disabled
            {% endif %}
          >
            <span>
              {%- if product.selected_or_first_available_variant.available == false or quantity_rule_soldout -%}
                {{ 'products.product.sold_out' | t }}
              {%- else -%}
                {{ 'products.product.add_to_cart' | t }}
              {%- endif -%}
            </span>
            {%- render 'loading-spinner' -%}
          </button>

{%- endform -%}
If my solution fixed your issue, please mark my solution as solved.
In need of custom solutions? Please DM.

View solution in original post

Replies 2 (2)

lunaworks
Shopify Partner
452 44 48

This is an accepted solution.

You need to find the featured collection liquid file and then the position where you want to add the add to cart button and do something like this 

{%- form 'product', product, class: 'form', novalidate: 'novalidate',
        data-type: 'add-to-cart-form'
      -%}
<input
          type="hidden"
          name="id"
          value="{{ product.selected_or_first_available_variant.id }}"
          {% if product.selected_or_first_available_variant.available == false or quantity_rule_soldout %}
            disabled
          {% endif %}
          class="product-variant-id"
        >
<button
            id="ProductSubmitButton-{{ section_id }}"
            type="submit"
            name="add"
            class="product-form__submit button button--full-width {% if show_dynamic_checkout %}button--secondary{% else %}button--primary{% endif %}"
            {% if product.selected_or_first_available_variant.available == false or quantity_rule_soldout %}
              disabled
            {% endif %}
          >
            <span>
              {%- if product.selected_or_first_available_variant.available == false or quantity_rule_soldout -%}
                {{ 'products.product.sold_out' | t }}
              {%- else -%}
                {{ 'products.product.add_to_cart' | t }}
              {%- endif -%}
            </span>
            {%- render 'loading-spinner' -%}
          </button>

{%- endform -%}
If my solution fixed your issue, please mark my solution as solved.
In need of custom solutions? Please DM.
Skence
Explorer
52 0 14

Thank you, Lunaworks!!!