Using metafields to show different washing instructions

Noe_Zoe_Berlin
New Member
5 0 0

Hello,

we added metafields to our product for care instructions. We have 3 different care instructions for our products. These are specified in the metafield by the numbers 1-3. Now we want to replace the number with a specified text. For instance if the metafield contains the number "2", it should be replaced with "Hand wash only". Something like: if metafield value is "2", display text "Hand wash only".

wash1 = 30 Degree, mild detergents

wash2 = Hand wash only

wash3 = 60 Degree, no bleach

We added the metafield to the code to product-template-liquid. 

We created an if statement like this:

    {% if product.metafield.wash.instructions contains '2' %}
    {% include 'wash2' %}
    {% endif %}

We created a washing-instructions.liquid snippet like this:

{% assign wash1 = '30 Degree, mild detergents' %}

{% assign wash2 = 'Hand wash only' %}

{% assign wash3 = '60 Degree, no bleach' %}

 

Any help is much appreciated, many thanks and all the best from Berlin.

Sam

0 Likes
Jason
Shopify Expert
10360 158 2003

It looks like your code is almost correct - but it has a tiny error.

It should be this:

{% if product.metafields.wash.instructions contains '2' %}

(metafields not metafields).

Why did you opt for metafields and not tags here?

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes
Noe_Zoe_Berlin
New Member
5 0 0

Thanks, that one worked. 

{{ product.metafields.wash.instructions }}
    {% if product.metafields.wash.instructions contains '1' %}
    {% include 'wash1' %}
    {% endif %}
    {% if product.metafields.wash.instructions contains '2' %}
    {% include 'wash2' %}
    {% endif %}

How do I get rid of the number "1" which is still displayed on output?

0 Likes
Noe_Zoe_Berlin
New Member
5 0 0

We tried inserting "remove: '1'", but still ending up with "1" in the text field. Any ideas?

 {{ product.metafields.wash.instructions }}
    {% if product.metafields.wash.instructions == '1' %}
    {% include 'wash1' | remove: '1' %}
    {% endif %}
    {% if product.metafields.wash.instructions contains '2' %}
    {% include 'wash2' %}
    {% endif %}

0 Likes
Jason
Shopify Expert
10360 158 2003

You're outputting the metafield value on the first line:

{{ product.metafields.wash.instructions }}

 

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes
Noe_Zoe_Berlin
New Member
5 0 0

Stupid us. Thanks a lot, we just found it ourselves!!

0 Likes
Alianovina
New Member
1 0 0

A square with a circle inside means that the Wash clothing as infrequently as possible, while the number of by filling up the washing machines each cycle save washingears energy. Wash at a low temperature, two dots for medium, and three for high heat setting. No dot means that you can tumble dry your clothes on any heat. then reduce the amount of detergent and follow the instructions on your detergent's label.

0 Likes