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
As a business owner, have you ever wondered when your customer's first impression of yo...
By Skye Jun 6, 2023We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023