Answers.Body: <p>I think you're asking how to output custom fields based on their type.</p>
  
  <p>Something like this should work:</p>
  
  <pre><code>{% for lineItem in cart.lineItems %} 
  
  // Is the current line item a variant purchasable?
  {% if className(lineItem.purchasable) == 'craft\commerce\elements\Variant' %}
  
    {% switch lineItem.purchasable.product.type.handle %}
      {% case "clothing" %}
          // Only output the varHeight if the product type is clothing
          {{ lineItem.description }}&lt;br&gt;
          Var Height: {{ lineItem.purchasable.varHeight }}
      {% default %}
          {{ lineItem.description }}
    {% endswitch %}
  
  {% else %}
  
    // Non variant purchasable
    {{ lineItem.description %}
  
  {% endif %}
  
  {% endfor %} 
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-27T14:32:36.570Z
Answers.Text: So far that is not working. I replaced "clothing" with my product type "wallpaper". Is there anything else I need to adjust? And I assume this should be within the {% for item in cart.lineItems %} {% endfor %} tags?
Answers.UserDisplayName: glider
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-19T04:46:42.527Z
Answers.Text: Just fixed the example. Better?
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-27T02:30:01.637Z
Answers.LastActivityDate: 2020-03-19T04:46:32.123Z
Answers.LastEditDate: 2020-03-19T04:46:32.123Z
Answers.UserDisplayName: Luke Holder
Body: <p>I'm trying to pass variants to the cart page. They variant field I want to pass is 'varHeight'. I'm using:</p>
  
  <pre><code>&lt;form method="POST"&gt;
    &lt;input type="hidden" name="action" value="commerce/cart/update-cart"&gt;
     {{ redirectInput('shop/cart') }}
     {{ csrfInput() }}
    {% for item in cart.lineItems %}
     ...
    {{ item.description }}
    {% for lineItem in cart.lineItems %} 
     {{ lineItem.purchasable.varHeight }}
    {% endfor %} 
      ...
    {% endfor %} 
  </code></pre>
  
  <p>This works but puts the 'varHeight' value on every product in the cart instead of just the product it relates to. I'm sure it's simple but need some input on how to do this.</p>
  
Tags: <plugin-craftcommerce>
Title: Passing variants to cart in Commerce
ThreadText: # Passing variants to cart in Commerce
  
  (Asked by: username_0 on 2020-02-26)
  
  I'm trying to pass variants to the cart page. They variant field I want to pass is 'varHeight'. I'm using:
  
  ```
  <form method="POST">
    <input type="hidden" name="action" value="commerce/cart/update-cart">
     {{ redirectInput('shop/cart') }}
     {{ csrfInput() }}
    {% for item in cart.lineItems %}
     ...
    {{ item.description }}
    {% for lineItem in cart.lineItems %} 
     {{ lineItem.purchasable.varHeight }}
    {% endfor %} 
      ...
    {% endfor %} 
  
  ```
  
  This works but puts the 'varHeight' value on every product in the cart instead of just the product it relates to. I'm sure it's simple but need some input on how to do this.
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-02-27. Score: 1
  
  I think you're asking how to output custom fields based on their type.
  
  Something like this should work:
  
  ```
  {% for lineItem in cart.lineItems %} 
  
  // Is the current line item a variant purchasable?
  {% if className(lineItem.purchasable) == 'craft\commerce\elements\Variant' %}
  
    {% switch lineItem.purchasable.product.type.handle %}
      {% case "clothing" %}
          // Only output the varHeight if the product type is clothing
          {{ lineItem.description }}<br>
          Var Height: {{ lineItem.purchasable.varHeight }}
      {% default %}
          {{ lineItem.description }}
    {% endswitch %}
  
  {% else %}
  
    // Non variant purchasable
    {{ lineItem.description %}
  
  {% endif %}
  
  {% endfor %} 
  
  ```
  
  > **Comments:**
  > **username_0**: So far that is not working. I replaced "clothing" with my product type "wallpaper". Is there anything else I need to adjust? And I assume this should be within the {% for item in cart.lineItems %} {% endfor %} tags?  
  > **username_1**: Just fixed the example. Better?  
  
  ---
  
  