Ask customer for additional information

From Shopify Wiki

Jump to: navigation, search

When you update the content of a cart or click the checkout button on a standard Shopify cart.liquid page, Shopify looks for two special parameters called note and attributes to include with the order.

Note

Imagine that you’re running a gift shop and you want to ask your customers for a note to be included in the package.

To get that functionality, add the following html/liquid code to your cart.liquid after <form> and before the </form> tag:

<p>
  <label for="note">Gift note:</label><br/>
  <textarea name="note" id="note" rows="3" cols="60">{{cart.note}}</textarea>
</p>

Image:gift-note.png

After placed and paid, this order will display the note in the Shopify admin.

Image:gift-order.png

Note Attributes

Note Attributes let you attach arbitrary values to an order, making them useful for creating more complex forms with checkboxes, drop-downs or even hidden fields which just attach the browser version or operating system of the client to the order.

Create them by using the name attribute on input elements:

 <input type="checkbox" name="attributes[wrapping]" value="yes" />

Note that note attributes may not be nested, so attributes[wrapping][fabric] or attributes[wrapping][style] will not work as expected. (The notes attributes are flattened to a single level.)

As an example, let’s ask the customer if they want their gift wrapped:

<p>
  <input type="checkbox" name="attributes[wrapping]" value="yes" {% if cart.attributes.wrapping %} checked="checked"{% endif %} />
  <label for="wrapping">Please wrap the products in this order:</label>
</p>

Image:gift-wrapping-note.png

This order, after it’s placed and paid, will display the following note in the Shopify admin:

Image:gift-wrapping-order.png

You can add as many attributes as you like, but each attributes[name] must be unique.

Another Example for Attach Notes

A shop sells conference tickets (the products), with attendance times (e.g. 'Saturday', 'Sunday', 'Entire Conference') stored as variants.

{% for item in cart.items %}

  {% for i in (1..item.quantity) %}
 
  <h4>{{ item.variant.title }}</h4>
  
  <dl>
    <dt>Name you wish to appear on your badge:</dt>
    <dd><input type="text" name="attributes[{{ item.variant.title }} Attendee Badge]" value="" id="badge"></dd>
  </dl>

  {% endfor %}

{% endfor %}
Personal tools