Flop
March 21, 2025, 10:09am
1
Hey @Flop ,
Based on your code, you need a meta field that can store multiple benefit entries, each with an image and text.
For Shopify products, you can use a metafield with the following settings:
Create a metafield definition in your Shopify admin:
Namespace: product_benefits
Key: benefits_list
Type: JSON
Description: “Product benefits with image and text”
The JSON structure should be an array of objects, each containing an image URL and text:
[
{
"image": "https://cdn.shopify.com/s/files/1/0548/9164/2935/files/kreuz_Medical_17aa3fd3-fc82-4725-89d2-59f67ed...",
"text": "Hohe Qualität"
},
{
"image": "https://cdn.shopify.com/s/files/1/0548/9164/2935/files/kreuz_Medical_17aa3fd3-fc82-4725-89d2-59f67ed...",
"text": "Schneller Versand"
}
]
Then, you can use Liquid code in your product template to dynamically generate your HTML:
{% if product.metafields.product_benefits.benefits_list %}
<div class="sh-product-benefits-container">
{% assign benefits = product.metafields.product_benefits.benefits_list %}
{% for benefit in benefits %}
<div class="sh-product-benefits-row">
<img src="{{ benefit.image }}" alt="Benefit {{ forloop.index }}" class="sh-product-benefits-img">
<span class="sh-product-benefits-text">{{ benefit.text }}</span>
</div>
{% endfor %}
</div>
<style>
/* Your existing CSS here */
.sh-product-benefits-container {
width: fit-content;
padding: 0px 0px;
background-color: #ffffff;
border-radius: 0px;
margin-top: -20px;
margin-bottom: 0px;
}
.sh-product-benefits-row {
display: flex;
align-items: center;
margin: 8px 0;
padding: 0px 0px;
background-color: #ffffff;
color: #000000;
border-radius: 30px;
width: fit-content;
}
.sh-product-benefits-img {
width: 17px;
margin-right: 8px;
height: auto;
margin-block: unset !important;
}
.sh-product-benefits-text {
flex: 1;
padding-top: 2px;
font-size: 16px;
}
</style>
{% endif %}
This approach allows you to:
Add different benefits for each product
Update all benefits from a single location
Maintain consistent styling across products
Use the same image multiple times without duplicating code
Feel free to reach out on our email if you have any more questions for us.
Cheers!
Shubham | Untechnickle