<p>Your <code>customColor3a</code> and <code>customColor3b</code> variables will always be <code>defined</code> so you need to check if <code>empty</code>.</p>

<pre><code>{% if item.options.customColor3a is defined and item.options.customColor3a is not empty %} |
    Custom Color 1: {{ item.options.customColor3a }} 
{% endif %}
{% if item.options.customColor3b is defined and item.options.customColor3b is not empty%} |
    Custom Color 2: {{ item.options.customColor3b }} 
{% endif %}
</code></pre>

CC BY-SA 4.0
2020-05-14T21:43:36.297Z
2020-05-14T21:43:36.297Z
Oli
<p>I have a custom field that allows customers to order a sample from a list of all products. It also allows a custom value to be entered for a custom color. I conditionally show/hide the fields with javascript and all the options are available on one product type. This works great except for one thing. On the admin emails it shows every option even if nothing was filled out. I have the labels set to only show if there is a value but they still output. </p>

<p>Here is the product type code:</p>

<pre><code>    &lt;select name="purchasableId"&gt;
        &lt;option&gt;Please Select Sample Type&lt;/option&gt;
        {% for purchasable in product.variants %}
        &lt;option {% if purchasable.stock &lt;= 0 and purchasable.hasUnlimitedStock == false %}disabled {% endif %}
                value="{{ purchasable.id }}"&gt;{{ purchasable.description }} {{ purchasable.price|commerceCurrency(cart.currency) }}&lt;/option&gt;
        {% endfor %}
    &lt;/select&gt;

    {# pattern #}
    &lt;select name="options[pattern3a]"&gt;
      &lt;option value=""&gt;Select Wallpaper Sample 1&lt;/option&gt;
      {% for product in craft.products.type('wallpaper').all() %}
      &lt;option value="Sample - {{ product.title }}"&gt;{{ product.title }} &lt;/option&gt;
      {% endfor %} 
    &lt;/select&gt;
   &lt;select name="options[pattern3b]"&gt;
      &lt;option value=""&gt;Select Wallpaper Sample 1&lt;/option&gt;
      {% for product in craft.products.type('wallpaper').all() %}
      &lt;option value="Sample - {{ product.title }}"&gt;{{ product.title }} &lt;/option&gt;
      {% endfor %} 
    &lt;/select&gt;

    {# custom color #}
    &lt;p&gt;&lt;strong&gt;Enter Your Custom Color Options&lt;/strong&gt;&lt;/p&gt;
    &lt;input type="text" name="options[customColor3a]" placeholder="Custom Color 1" value=""&gt;
</code></pre>

<p>And this is what I use on the admin emails:</p>

<pre><code>{% for item in order.lineItems %}
{% if item.purchasable.product.type.hasVariants %}
...
&lt;strong&gt;{{ item.description }}&lt;/strong&gt;  
{% if item.options.pattern | length %}
    {{ item.options.pattern }} | 
{% endif %}

{% if item.options.customColor3a is defined %} |
    Custom Color 1: {{ item.options.customColor3a }} 
{% endif %}
{% if item.options.customColor3b is defined %} |
    Custom Color 2: {{ item.options.customColor3b }} 
{% endif %}
...         
</code></pre>

<p>And finally, on the emails it looks like this:</p>

<p>Sample 1 - Product Name, 
Custom Color 1: Green | Custom Color 2:  </p>

<p>So I basically just want to hide the labels if nothing was selected. In the case above just not output "Custom Color 2". Any help would be appreciated!</p>

<plugin-craftcommerce><plugin-craftcommerce3>
Commerce custom field output
# Commerce custom field output

(Asked by: username_0 on 2020-05-14)

I have a custom field that allows customers to order a sample from a list of all products. It also allows a custom value to be entered for a custom color. I conditionally show/hide the fields with javascript and all the options are available on one product type. This works great except for one thing. On the admin emails it shows every option even if nothing was filled out. I have the labels set to only show if there is a value but they still output. 
Here is the product type code:
    
        Please Select Sample Type
        {% for purchasable in product.variants %}
        {{ purchasable.description }} {{ purchasable.price|commerceCurrency(cart.currency) }}
        {% endfor %}
    

    {# pattern #}
    
      Select Wallpaper Sample 1
      {% for product in craft.products.type('wallpaper').all() %}
      {{ product.title }} 
      {% endfor %} 
    
   
      Select Wallpaper Sample 1
      {% for product in craft.products.type('wallpaper').all() %}
      {{ product.title }} 
      {% endfor %} 
    

    {# custom color #}
    Enter Your Custom Color Options
    

And this is what I use on the admin emails:
{% for item in order.lineItems %}
{% if item.purchasable.product.type.hasVariants %}
...
{{ item.description }}  
{% if item.options.pattern | length %}
    {{ item.options.pattern }} | 
{% endif %}

{% if item.options.customColor3a is defined %} |
    Custom Color 1: {{ item.options.customColor3a }} 
{% endif %}
{% if item.options.customColor3b is defined %} |
    Custom Color 2: {{ item.options.customColor3b }} 
{% endif %}
...         

And finally, on the emails it looks like this:
Sample 1 - Product Name, 
Custom Color 1: Green | Custom Color 2:  
So I basically just want to hide the labels if nothing was selected. In the case above just not output "Custom Color 2". Any help would be appreciated!

**Tags:** plugin-craftcommerce, plugin-craftcommerce3


---

## 1 answers

### Answer by username_1 on 2020-05-14. Score: 2 | Accepted answer

Your customColor3a and customColor3b variables will always be defined so you need to check if empty.
{% if item.options.customColor3a is defined and item.options.customColor3a is not empty %} |
    Custom Color 1: {{ item.options.customColor3a }} 
{% endif %}
{% if item.options.customColor3b is defined and item.options.customColor3b is not empty%} |
    Custom Color 2: {{ item.options.customColor3b }} 
{% endif %}


---

