[英]Display Product Variant Metafields
I need to display metafields based on the variants selected on the product page. 我需要根据产品页面上选择的变体显示元字段。 I want them to change as the variants are clicked.
我希望它们随着点击变体而改变。 I may need some jquery help but I am not that sure how to apply with liquid.
我可能需要一些jQuery帮助,但是我不确定如何使用液体。 Below is my code, any help is greatly appreciated!
以下是我的代码,非常感谢您的帮助!
{% for variant in product.variants %}
<div id="tab{{ forloop.index0 }}" class="zr-tabs-panel {% if forloop.first == true %}js-active{% endif %}">
<div class="table-responsive>">
<table class="table table-striped">
<tbody>
{% for field in current_variant.metafields.var_meta %}
<tr>
<td>{{ field | first }}</td>
<td>{{ field | last }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endfor %}
The short answer is that you will need to (a): Expose your meta fields to your site's javascript somehow, then (b): Update your variant-changing code to also update the section based on your meta fields. 简短的答案是,您将需要(a):以某种方式将元字段公开到网站的javascript中,然后(b):更新变体更改代码,并根据元字段也更新该部分。
In many themes, the variant-changing code is contained in a function named selectCallback (though this isn't the case in all themes - if you have trouble finding this code, you can try reaching out to your theme's developer for theme-specific advice). 在许多主题中,变体代码包含在名为selectCallback的函数中(尽管并非在所有主题中都如此-如果找不到此代码,则可以尝试与主题的开发人员联系以获取主题特定的建议)。
Whenever you're using Liquid code to put values into Javascript code, I strongly recommend using the json
filter - Liquid's magic filter that ensures your output will always be Javascript-legal. 每当您使用Liquid代码将值放入Javascript代码时,我强烈建议您使用
json
过滤器-Liquid的魔术过滤器,以确保您的输出始终是Javascript合法的。 (Quotation marks and line breaks will be properly escaped, empty values will be printed as null
, etc) (引号和换行符将被正确转义,空值将被打印为
null
等)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.