Liquid主题产品字段项目添加到购物车

huangapple go评论105阅读模式
英文:

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

          &lt;p class=&quot;line-item-property__field&quot;&gt;
  &lt;label for=&quot;your-name&quot;&gt;Your name&lt;/label&gt;
  &lt;textarea required class=&quot;required&quot; id=&quot;your-name&quot; name=&quot;properties[Your name]&quot;&gt;&lt;/textarea&gt;
&lt;/p&gt;

and then I have added this to main-cart-items.liquid

{% assign property_size = item.properties | size %}
{% if property_size &gt; 0 %}
  {% for p in item.properties %}
    {% assign first_character_in_key = p.first | truncate: 1, &#39;&#39; %}
    {% unless p.last == blank or first_character_in_key == &#39;_&#39; %}
      {{ p.first }}:
      {% if p.last contains &#39;/uploads/&#39; %}
        &lt;a class=&quot;lightbox&quot; href=&quot;{{ p.last }}&quot;&gt;{{ p.last | split: &#39;/&#39; | last }}&lt;/a&gt;
      {% else %}
        {{ p.last }}
      {% endif %}
      &lt;br&gt;
    {% 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 }}"

huangapple
  • 本文由 发表于 2023年2月27日 05:33:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75575148.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定