英文:
Liquid theme product field item to cart
问题
我一直在尝试向我的产品添加自定义字段,它显示在产品页面但不显示在购物车中。
我一直在按照以下步骤进行操作:https://community.shopify.com/c/shopify-design/product-pages-get-customization-information-for-produ...
我在main.product.liquid中添加了一个示例字段
<p class="line-item-property__field">
<label for="your-name">Your name</label>
<textarea required class="required" id="your-name" name="properties[Your name]"></textarea>
</p>
然后我将这个内容添加到main-cart-items.liquid
{% assign property_size = item.properties | size %}
{% if property_size > 0 %}
{% for p in item.properties %}
{% assign first_character_in_key = p.first | truncate: 1, '' %}
{% unless p.last == blank or first_character_in_key == '_' %}
{{ p.first }}:
{% if p.last contains '/uploads/' %}
<a class="lightbox" href="{{ p.last }}">{{ p.last | split: '/' | last }}</a>
{% else %}
{{ p.last }}
{% endif %}
<br>
{% endunless %}
{% endfor %}
{% endif %}
我已经没有更多的想法,有人可以帮助吗?
英文:
I have been trying to add a custom field to my product and it's showing in product page but not in the cart.
I have been going through the steps from : https://community.shopify.com/c/shopify-design/product-pages-get-customization-information-for-produ...
I have added an example field in main.product.liquid
<p class="line-item-property__field">
<label for="your-name">Your name</label>
<textarea required class="required" id="your-name" name="properties[Your name]"></textarea>
</p>
and then I have added this to main-cart-items.liquid
{% assign property_size = item.properties | size %}
{% if property_size > 0 %}
{% for p in item.properties %}
{% assign first_character_in_key = p.first | truncate: 1, '' %}
{% unless p.last == blank or first_character_in_key == '_' %}
{{ p.first }}:
{% if p.last contains '/uploads/' %}
<a class="lightbox" href="{{ p.last }}">{{ p.last | split: '/' | last }}</a>
{% else %}
{{ p.last }}
{% endif %}
<br>
{% endunless %}
{% endfor %}
{% endif %}
I am running out of ideas can someone help ?
答案1
得分: 1
以上用于处理行项目属性的代码已经在主题中,所以属性没有被发布,您需要将字段与表单关联起来,通常可以通过将字段放在{% form %}标签内或者通过将其与表单关联,例如使用属性form="{{ product_form_id }}"来实现。
英文:
The code above to handle the line item property is already in the theme, so the property isn't being posted, you need to associate the field with the form this usually can be done by having the field inside the {% form %} tag or else associated with the form by giving it the attribute form="{{ product_form_id }}"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论