Reading order attributes from within an unplaced order

Highlighted
Tourist
36 0 1

Hi,

 

I am trying to do the following:

Make a counter that counts a specific type of product and exports it into the cart attributes as additional details, but keeps adding the number globally.

So basically every time someone buys a red shoe, it places the number in cart attributes and displays in the order's additional details. (I have this part working) But with each order, it adds the current amount of red shoes in this order to a global variable and displays this variable. So, order#1 has 1 red shoes, so on the admin order page is will show 1 red shoe, but the next order they buy 3 red shoes, so then the additional details section will display 4 red shoes on order#2. Now, order #3 has no red shoes so it wont display anything... etc.

 

Here is what I have so far!

{% assign start_count = 0 %}     
{% for item in cart.items %}            
    {% if item.product.tags contains "red shoe"  %}       
         {% capture temp %}{{ start_count | plus: item.quantity }}{% endcapture %} 
    {% endif %}
    {% assign end_count = temp %}

 
{% endfor %} 
            <div class="red-shoe-counter">
                   <input type = "hidden" name="attributes[Red Shoe Count]" value = "{{ end_count }}">
                  </div>
            
            

Can I store end_count in a snippet or something? so it just keeps counting instead of resetting every time the cart is sent to order status?

0 Likes