skip to Main Content

I’ve tried many different ways, and nothing seems to add my custom field on my cart to the cart attributes like everywhere says you can. I don’t understand. I’ve even used Shopify’s UI generator and THAT’s not working either. Here is the code I add:

<p class="cart-attribute__field">
    <label for="your-name">Your name</label>
    <textarea required class="required" id="your-name" name="attributes[Your name]">{{ cart.attributes["Your name"] }}</textarea>
</p>  

Then I’ve tried this:

<div style="width:300px; clear:both;">
  <p>
    <label for="delivery_date">Pick a delivery date:</label>
    <input required class="required" id="delivery_date" type="text" name="attributes[delivery_date]" value="{{ cart.attributes.delivery_date }}" />
    <span style="display:block" class="instructions"> We do not deliver during the weekend.</span>
  </p>
</div>

That doesn’t work either, it has something to do with the attributes but I can’t figure out what.

Anyone?

2

Answers


  1. In the liquid cart section, inside <form> tag you should add input or textarea with name attribute note.

    For example:

    ...
    <form action="/cart" method="post" novalidate>
    ...
        <textarea name="note">{{ cart.note }}</textarea>
    ...
    </form>
    
    Login or Signup to reply.
  2. If you’ve pasted your code inside the <form>...</form> tags then the issue I see with your code is that setting the value is wrong:

    <div style="width:300px; clear:both;">
      <p>
        <label for="delivery_date">Pick a delivery date:</label>
        <input required class="required" id="delivery_date" type="date" name="attributes[delivery_date]" value="{{ cart.attributes["delivery_date"] }}" />
        <span style="display:block" class="instructions"> We do not deliver during the weekend.</span>
      </p>
    </div>
    

    You can see this working at a development store: https://kotn-eu.myshopify.com pwd skufom

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search