All things Shopify and commerce
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hi!
I'm looking to mark specific product variants as new.
Example. We have products available in multiple color. Some color are new, and others no. If we want to make specific colors as new "product", how can we do it without marking the product itself as new?
Thank you!!
Do you want to do it manually or automatically?
Anyway, you'd need to have a variant metafield which will contain this data.
You can use an app to show content of this metafield as your visitors select this variant.
On most themes it is also possible to implement this with 'Custom liquid' block, similar to this solution
To automate setting of the metafield you may use Flow app -- start with trigger "Product variant added", then set variant metafield content, then wait for, say 30 days and remove this metafield content:
The code from the linked post can be amended like this to work with the flow above (this is designed to work for Dawn and expected to work in other free Shopify 2.0 themes). The code should go into "Custom liquid" block inside product info section.
<div class="custom-description">
{{ product.selected_or_first_available_variant.metafields.custom.new-variant }}
</div>
<script>
window.addEventListener('DOMContentLoaded', () => {
subscribe (PUB_SUB_EVENTS.variantChange, (event) => {
const { html, variant, sectionId } = event.data;
debugger;
const source = html.querySelector(`[data-section=${sectionId}] .custom-description`);
const destination = document.querySelector(`[data-section=${sectionId}] .custom-description`);
if (source && destination) destination.innerHTML = source.innerHTML;
});
});
</script>