Hi,
I am trying to figure out how to display a custom description for certain product variants.
Per context: Most product descriptions state that products will be shipped within 2-7 working days. However, some variants of products are immediately available for dispatch. I figured that the best approach for this, is to use metafields. I’ve already installed the ‘Metafields Guru’ app, but am still a bit confused as to how I can apply a Metafield to certain variants.
Would anyone be able to help me out? Appreciate it a lot!
That’s indeed what I meant! When I apply a Metafield to a product, it works fine. But for variant-specific metafields, it does not show up. Thanks for the article though, too bad I do not understand any of it regarding coding
Yeah, the code is a bit complicated. You need the javascript connected to the variant selector to pick up when it changes.
This code from the other post should work to display all the variant metafields, if you put it somewhere in your product.liquid or product-template file:
You can do this via custom coding. Store the variant description in metafields, detect when a variant is changed, pull the new description from metafield, and update your product description.
Detecting the variant change depends on how your store is handling this in JavaScript. But should not be really hard for a developer to set this up.
There is an app (written by me) that does this out of the box for you: https://apps.shopify.com/dynamic-variant-description. It will handle the descriptions with a nice rich text editor, detect the variant change and update the product description. Feel free to give it a try and let me know if this works for you.
for the Dawn theme the code is in the global.js file in the Assets folder. Look for the onVariantChange() on around line 570. You can do something like this (add updateMeta()):
At the end of this post is a screen shot of what we are displaying.
Our goal is to display a ‘per unit’ price by taking the variant price and dividing it by our custom variant metafield named: variant.metafields.my_fields.sku_variant_unit_qty
Instead of giving your sku_variant_unit_qty metafield a value of 4, or whatever it is, just give it a value of “4 ($20 per unit)”. This involves you calculating the unit price yourself. If you want more control over where to position the price, then maybe create a second variant metafield for the calculated unit price.
To do the price calculation in the code, change the {% capture %} liquid code to:
Hi, I read this kind of solution a couple times now but the Dawn theme doesn’t have the onVariantChange() part in the file anymore /for several months according to others). Is there a new solution for this?
I have updated the metafields and variant metafields data, but how do I get it to show on my store front. I have tried many attempts but they all seem to be outdated. Any help is appreciated.
Hi. I haven’t looked at this for a long time, I guess the code has changed a lot since then. Let me know exactly what you need to do, I can try to help