5

In the cart example code the selected options are displayed in an unformatted list like so:

{{ item.options|json_encode }}

I noticed that the note field text could be outputted individually like so:

{{ item.note }}

I'm looking to do the same for the select fields on my product, so if I had a list of options like the gift wrap example, how would I then output the result individually (so that I can format how I like)?

<select name="options[giftWrapped]">
  <option value="no">No gift wrap.</option>
  <option value="yes">Gift wrapped.</option>
</select>
Dan Lee
  • 1,107
  • 7
  • 22

2 Answers2

6

Answer is the example code for the cart:

{{ item.options.giftWrapped }}
Dan Lee
  • 1,107
  • 7
  • 22
5

You can also loop through each object within the options array using:

{% for key, value in item.options %}
  {{ key }} - {{ value }}
{% endfor %}
Luke Pearce
  • 3,863
  • 1
  • 11
  • 25