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
Benutzer | RANKING |
---|---|
17 | |
11 | |
10 | |
10 | |
9 |
Online-Marketing für einen Shopify-Shop kann manchmal wie ein Minenfeld erscheinen und vie...
By Gabe Dec 1, 2023In diesem Leitartikel werden wir erläutern, warum es wichtig ist, dein Shop als vertrauens...
By Kai Oct 25, 2023Dieser Blog-Beitrag ist eine Zusammenfassung des Webinars Vorbereitung auf BFCM: ein Webi...
By Jacqui Oct 10, 2023