Formula for adding the values of a integer list metafield together

Solved

Formula for adding the values of a integer list metafield together

meganatmetro
Excursionist
28 4 8

As the title says, I am looking for a formula to add the values of a single metafield together.

 

We have a product that we sell in blowout, so it contains multiple lengths of the same product (such as 5ft, 3ft, 10ft, 1ft). I am able to list the individual lengths, but at the end of my list, I would like to display the total linear length.

Accepted Solution (1)

meganatmetro
Excursionist
28 4 8

This is an accepted solution.

Figured it out

{% assign lengths = product.metafields.custom.lengths.value %}
 
{% assign sum = 0 %}
  {% for length in lengths %}
      {% assign sum = sum | plus: length %}
  {% endfor %}

View solution in original post

Reply 1 (1)

meganatmetro
Excursionist
28 4 8

This is an accepted solution.

Figured it out

{% assign lengths = product.metafields.custom.lengths.value %}
 
{% assign sum = 0 %}
  {% for length in lengths %}
      {% assign sum = sum | plus: length %}
  {% endfor %}