Easy way to pass/fetch additional information to Cart?

New Member
2 0 0

I have some products that have variations called "Additional Points", and the customer can select 0,1,2,3,4.

When the user has 1,2,3 or 4 selected, i would like to make a required text box appear on the cart page to enter information about these additional points.

So far, I have achieved this by editing;


                        {%- for line_item in cart.items -%}
                        {%- if line_item.sku == 'VARIANT-SKU' -%}
                        <p class="cart-attribute__field">
                              <label for="additional-points">Additional  Points</label>
                              <textarea required class="required" id="additional-points" name="attributes[Additional  Points]">{{ cart.attributes["Additional Points"] }}</textarea>
                        {%- endfor -%}


This works fine, and when the product with SKU 'VARIENT-SKU' is in the cart, it appears and works perfectly. However I have 50+ of these variants, and checking each lineitem against a list of 50+ SKU's is a silly way to do this.

I believe the simplest way to do this is, is to give each variant a meta field.  e.g. - product.metafields.additional-info.additional-points.yes  and add the input box whenever this metafield is detected.

However, products are added as lineitems in the cart, so dont have the metafields, so assuming i have the productID or SKU from the lineitem in the cart page, how do I retrieve the product metafields?

Side note: I looked at option of sending the metafield as a lineitem.property but due to how out products are displayed using grouped/bundle products this isn't an option. 

New Member
2 0 0

Turns out i was being stupid.

line_item.product exists. Makes this simple.