Liquid, JavaScript, Themes
Hi, I would like to assemble a text per variant depending on tags and stock. The code only works when loading the page, but not when changing the variants.
{% assign current_variant = product.selected_or_first_available_variant %}
{% if current_variant.inventory_quantity > 0 %}
... {{ current_variant.inventory_quantity }} ...
{% endif %}
How can I force the page to reload when changing the variant or how do I have to rewrite liquid? It also works somehow with the price.
After hours of searching .. this is my simple solution in the global.js
renderProductInfo() {
...
const destinationMYpart = document.getElementById(`mypart-${this.dataset.section}`);
const sourceMYpart = html.getElementById(`mypart-${this.dataset.originalSection ? this.dataset.originalSection : this.dataset.section}`);
if (sourceMYpart && destinationMYpart) destinationMYpart.innerHTML = sourceMYpart.innerHTML;
...
where you can replace the "mypart" with your name.
Hey @hennott
Well done in finding a great solution which might help others here in the community too!
Gabe | Social Care @ Shopify
- War meine Antwort hilfreich? Klicke Like um es mich wissen zu lassen!
- Wurde deine Frage beantwortet? Markiere es als Akzeptierte Lösung
- Um mehr zu erfahren, besuche das Shopify Help Center oder den Shopify Blog
Hallo zusammen! Wir haben intensiv daran gearbeitet, dein Shopify-Erlebnis auf Deutsc...
By JasonH May 12, 2025Mit dem Lernpfad der Shopify Academy und dem Verified Skills-Badge Expanding Your Sho...
By Shopify Feb 7, 2025Den Verkauf im Großhandel steigern: In der Shopify Academy lernst du, wie das geht, zum...
By Shopify Feb 3, 2025