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
Teil 2 - Wie die Prinzipien des UX-Designs dir dabei helfen können einen großartigen Shop ...
By Kai Sep 16, 2024Teil 1 - Wie die Prinzipien des UX-Designs dir dabei helfen können einen großartigen Shop ...
By Kai Sep 9, 2024Anpassungen des benutzerdefinierten Codes an Shopify-Themes (CSS) leicht gemachtIn diesem...
By Gabe Aug 28, 2024