如何解决如何根据选项值显示 Shopify 变体
如何根据选项的值在 Shopify 的产品和系列页面上仅显示某些变体?
假设选项名称是“Box Options”并且值是“Trade”或“Retail”,我希望类似于此代码的内容返回 Trade 变体的价格:
{%- assign get_variant = product.options_with_values -%}
{% assign Trade_variant = get_variant | where: "Trade" %}
<p>{{ Trade_variant.price }}</p>
对于上下文,我正在尝试使用液体文件中的 if 语句在客户标签为“Trade”的情况下使用交易价格:
{% if customer.tags contains 'Trade' %}
感觉这应该很容易,但对于我的生活,我无法让它发挥作用。
解决方法
如果你的变体只包含一个选项,那么类似的东西应该可以工作(未经测试):
{% if customer.tags contains 'Trade' %}
{% assign p_variants = product.variants | where:'title','Trade' %}
{% for variant in p_variants %}
{{ variant.title }}
{% endfor %}
{% endif %}
然后,第二种情况,你的变体有多个选项,那么它有点复杂(也没有测试):
{% if customer.tags contains 'Trade' %}
{% for variant in product.variants %}
{% if variant.options contains 'Box Options' and variant.title contains 'Trade' %}
{{ variant.title }}
{% endif %}
{% endfor %}
{% endif %}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。