Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I set up several decimal Metafields in my store to store to display dimensions but the values are defaulting to display .0 at the end of the number. I only want it to show the decimal if there is actually a decimal value. Anyone know how to do this?
Here is an example:
Metafield Value = 12.0
The way I want it to display is = 12
Metafield Value = 12.05
The way I want it to display is = 12.05
Solved! Go to the solution
This is an accepted solution.
and I don't know if I understood correctly, but to join our codes, it would be
{% if product.metafields.my_fields.arm_h.value != blank %}
{% assign metafield_ceil = product.metafields.my_fields.arm_h.value | ceil %}
arm h. {% if metafield_ceil == product.metafields.my_fields.arm_h.value %} {{ product.metafields.my_fields.arm_h.value | round }} {% else %} {{ product.metafields.my_fields.arm_h.value }} {% endif %}
{% endif %}
hey, 4cexntr
try this where you are calling your code, replacing metafield_value with the variable that calls your metafield value:
{% assign metafield_ceil = metafield_value | ceil %}
{% if metafield_ceil == metafield_value %}
{{ metafield_value | round }}
{% else %}
{{ metafield_value }}
{% endif %}
Wow Uhrick! Thank you for responding and this worked but I'm hoping you might be able to help me with a combo of the code you wrote, plus what I already have.
The code I have now displays some text and the meta-value, but it's blank it wont show anything. Is there a way to combine the two so that it doesnt show the .0 and also doesnt show the value / text if blank?
Here is my current code:
{% if product.metafields.my_fields.arm_h.value != blank %}arm h. {{ product.metafields.my_fields.arm_h.value }}"
{% endif %}
is this comma after }} closing anything? And maybe try separating arm h. from %}, your code seems to be functional in general.
Other than that, if my answer helped, I'd appreciate if you could like it or mark as solution
This is an accepted solution.
and I don't know if I understood correctly, but to join our codes, it would be
{% if product.metafields.my_fields.arm_h.value != blank %}
{% assign metafield_ceil = product.metafields.my_fields.arm_h.value | ceil %}
arm h. {% if metafield_ceil == product.metafields.my_fields.arm_h.value %} {{ product.metafields.my_fields.arm_h.value | round }} {% else %} {{ product.metafields.my_fields.arm_h.value }} {% endif %}
{% endif %}
Worked perfectly. Thank you for your help!!!
Thank you for this solution. Can you tell me what file this code needs to go in?
hey, nelson. It should go in whatever file you need to get the metafields in. If you want them in the product page, there is probably a file called 'main-product.liquid' in the Section folder of your theme code
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024