Shopify themes, liquid, logos, and UX
Hi, I have created a Collection Metafield (single line with preset text to be selected). In my Sale collection aI have added this metafield and selected the text. Now how do I add this to the cart page in Impulse theme to display like the sample attached? So basically any products that are in the Sale collection I would like the red text to appear.
Hi @MCTP 👋 A collection metafield is available on collection templates, not directly on a product.
You have to go through all the line items > product > collections seeing if it's even in the relevant collection
https://shopify.dev/docs/api/liquid/objects/product#product-collections
Then output the collections metafield https://shopify.dev/docs/api/liquid/objects/collections
Put the following somewhere before the properties output.
Generally with the variants options titles output.
⚠💣 Always backup themes before changing files 💣⚠
{%- assign in_sale_collection = '' -%}
{%- for collection in line_item.product.collections -%}
{%- if collection.handle == "collection-handle" -%}
{%- assign in_sale_collection = collection -%}
{%- endif -%}
{%- endfor -%}
{%- if in_sale_collection -%} {{ collection['collection-handle'].metafields.namespace.key }} {%- endif -%}
Adjust namespace and key to need, and or use the .value accessor in some cases.
if the message is the same for all such items having this as metafield can be kinda moot /shrug
If your a merchant that need this customization implemented for you then contact me for services
Contact info in forum signature.
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail in ALL correspondence.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Do I need to use metafields? Could i just have code that if the compare price is being used than XX text will display?
Depends on need, a metafield does make the text part of the collection admin UI instead of rooting around in theme code for a line that could be harder to auto translate if not done as a locale translation ,etc.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Code exampoe has a typo, collection should be collections (plural, collections object accessor)
{{ collection['collection-handle'].metafields.namespace.key }}
should be
{{ collections['collection-handle'].metafields.namespace.key }}
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Thanks so much with helping me with this. I have done the following but it is not appearing. The mug is in the sale collection. I tried with .value and without.
From the look of the code "line_item" isn't needed and something has already set the "product" as a variable to work with?
So it may be product.product.collections ... 👨💻 which would be the silly result of the theme developers not properly differentiating between a line-item and a product.
Context matters step back and find out what "line_item" is in the rest of the code it could be just "item", or "lineitem" or "product".
Then start outputting it's property values then work to the product : item.title, item.product.handle, item.product.collections, etc etc tectto be sure you've got the right variable and can get to the need contexts.
👨💻It can help to view the source(ctrl+u) of the page instead of solely relying on the cart page to reload and paint each time.
Good Luck.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024