Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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
Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024Note: Customizing your CSS requires some familiarity with CSS and HTML. Before you cust...
By JasonH Aug 12, 2024