产品价格%折扣不随所选型号而变化

时间:2019-08-02 12:54:41

标签: shopify shopify-template

请帮助我解决此代码。我根据选择的变体显示了一些折扣,点击2件装和3件装后其价格不会改变,因为我们有不同的折扣%。这是我的shopify产品网址https://us.buywow.com/products/wow-apple-cider-shampoo-cocounut-oil-conditioner-set-500ml
编写了回调函数,但我不明白为什么它没有改变

Product.liquid

<!-- /templates/product.liquid -->
{% assign on_sale = false %}
{% if product.compare_at_price > product.price %}
{% assign on_sale = true %}
{% endif %}

.

.

.

.

{% comment %}
------ Product Price ------
{% endcomment %}
<div class="product_prices">
<span class="visually-hidden">{{ 'products.general.regular_price' | t }}</span>
<h4 id="ProductPrice" class="product-regular-price" itemprop="price" content="{{ current_variant.price | divided_by: 100.00 }}">
{{ current_variant.price | money }}
</h4>
<span class="old-price">{{ current_variant.compare_at_price | money }}</span>
{% if on_sale %}
<div class="save_money_block">
<span class="save_off">
{% if current_variant.compare_at_price > current_variant.price %}
{{ current_variant.compare_at_price | minus: current_variant.price | times: 100.0 |
divided_by: current_variant.compare_at_price | money_without_currency | times: 100
| replace: '.0', ''}}% OFF{% endif %}
</span>
</div>
{% endif %}
</div>

.

.

.

.

.

<script>
(function(s3d) {
if (!s3d) {
console.warn('"window.Shopify3d" does not exist. Please ensure you\'ve added the <script> to your theme');
return;
}
{% for variant in product.variants %}
s3d.mapMetafieldAssets('{{ variant.id }}', '{{ variant.metafields.shopify3d['assets'] }}');
{% endfor %}
})(window.Shopify3d);
</script>

<script>
var selectCallback = function(variant, selector) {
timber.productPage({
money_format: "{{ shop.money_format }}",
variant: variant,
selector: selector
});
};

</script>

在选择Pack Of 3-60%OFF时应得到结果。 不会发生自动刷新。

1 个答案:

答案 0 :(得分:0)

请记住,Liquid是在文档发送到客户端的浏览器之前在服务器端进行编译的,因此结果不是动态的,并且在选择变体后将无法自动更新。

为了在选择更改时使折合百分比部分发生适当的变化,您需要添加在变体选择更改时将运行的javascript代码。幸运的是,您已经有一个函数可以执行此操作,在您的主题中它恰好叫做selectCallback,然后调用了一个名为timber.productPage的函数来完成所有繁重的工作。

您将要使用更新您的百分比折扣字段所需的javascript代码来更新selectCallbacktimber.productPage。 (在您的情况下,后者可能是更好的选择,因为这样可以使所有相关的价格显示更新代码保持靠近。)variant参数可以是当前选择的变体,也可以是{{1} }如果当前选项选择与产品中的任何变型都不匹配; undefined参数将包含许多通常有用的信息,例如父产品对象。

希望这会有所帮助!

相关问题