skip to Main Content

Currently in my shopify code I can use a line item input like so:

line_item.variant.title

This will output the following:
Snapback / One Size Fits All / Camo

What I’m trying to do is to break up each one into it’s own line. So I can get this back:
Snapback
One Size Fits All
Camo

The challenge is that there are several products with different variants. Some contain the string “7/9” so I wouldn’t be able to use “/” as a delimiter. Any suggestions?

2

Answers


  1. The variant title is generated based on the variant options.

    So if you like to show the different options you just call the options instead of the title.

    Example:

    {{ variant.option1 }}<br/>
    {{ variant.option2 }}<br/>
    {{ variant.option3 }}
    

    Refer to the docs here: https://help.shopify.com/en/themes/liquid/objects/variant#variant-option1

    Login or Signup to reply.
  2. I found this one is a better solution to set this dynamically:

    {% if line.variant.title != 'Default Title' %}
       <span class="order-list__item-variant variant-title">
          {% assign variantOptions = line.variant.title | split: ' / ' %}
                
          {% assign count = 0 %}
            
          {% for option in line.product.options_with_values %}
                
            <span><b>{{ option.name }} :</b> {{variantOptions[count]}}</span>
                  <br />
                
            {% assign count = count | plus: 1 %}
                
         {% endfor %}
                
                <br />
    
        </span>
            
     {% endif %}
    

    As by default, we are getting / in the value of line.variant.title. So we need to split this first So that we can get individual option values. and because there is no feasible object to get option label so we need to use the
    line.product.options_with_values in a loop and iterate and set label with value as in the above code.

    So, just use this code in your order confirmation email and you will get the format in the email as follow. Here Embroidery as yes and no. and Border as Zigzag and Simple are the options for product variants.
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search