Liquid, JavaScript, themes, sales channels
Currently I am working on setting up a store with the Dawn 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. However, when I load in the following html+liquid below the pricing tag I get an error.
<product-form class="product-form">
{%- form 'product', product, data-productid: product.id, id: product_form_id, class: 'form', novalidate: 'novalidate', data-type: 'add-to-cart-form' -%}
<input type="hidden" name="id" data-productid="{{ product.id }}" value="{{ product.selected_or_first_available_variant.id }}">
<div class="product-form__buttons">
<button
type="submit"
name="add"
class="product-form__submit button button--full-width {% if block.settings.show_dynamic_checkout and product.selling_plan_groups == empty %}button--secondary{% else %}button--primary{% endif %}"
{% if product.selected_or_first_available_variant.available == false %}disabled{% endif %}
>
{%- if product.selected_or_first_available_variant.available -%}
{{ 'products.product.add_to_cart' | t }}
{%- else -%}
{{ 'products.product.sold_out' | t }}
{%- endif -%}
</button>
{%- if block.settings.show_dynamic_checkout -%}
{{ form | payment_button }}
{%- endif -%}
</div>
{%- endform -%}
</product-form>
I get the following error:
Liquid error (add-to-cart line 2): product form must be given a product
I hope someone can help with this.
Solved! Go to the solution
This is an accepted solution.
Hello @ThomKnepper ,
I already posted a answer here https://community.shopify.com/c/shopify-design/dawn-thene-2-0-add-to-cart-on-collection-page-with-aj...
Thanks
This is an accepted solution.
Hello @ThomKnepper ,
I already posted a answer here https://community.shopify.com/c/shopify-design/dawn-thene-2-0-add-to-cart-on-collection-page-with-aj...
Thanks
Brilliant! Thank you so much!
hey, it got added but it's not working, i mean it's not adding the items to the cart
User | RANK |
---|---|
12 | |
10 | |
7 | |
7 | |
6 |
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022