当用户在shopify中更改数量时,如何刷新购物车页面



我已经更新了使用js的方法,我还更新了脚本及其逻辑并粘贴在下面,看看你是否可以帮助我完成

我想根据购物车中的总价值或购物车中物品的数量在购物车页面顶部显示信息关于购物车价格/商品的实时信息

这是代码示例"quot">

{% if  cart.item_count == 0  %}
<p>FREE Gift Over <span>SAR 1000</span></p>
{% endif %}

{% if  cart.item_count > 99 %}
<p>Congratulations! You've got FREE GIFT</p>
{% endif %}

{% if  cart.item_count < 8 and  cart.item_count > 0 %}
<p>Congratulations! Youd12've got FREE GIFT</p>
{% elsif cart.item_count < 19 and  cart.item_count >= 8 %}
<p>Congratulations! Yodsuh45d've got FREE GIFT</p>

{% endif %} 
</div>

"quot"图像以更好地理解点击查看图像

黄色部分是我希望信息成为的地方

您想要做的是在数量输入中添加一个onchange事件监听器,它会更新您想要更新的页面片段,或者只触发页面重新加载

尝试将其转换为js,如果我们让脚本每5秒运行一次,那么它将每5秒从qtn获取数据,并根据这一点更新自己,你认为它会如何工作?"quot">

<p id="freeGift"></p>
<script>
const time = '{{cart.item_count}}';
let greeting;
if (time == 0) {
greeting = "FREE Gift Over SAR 1000";
} 
if (time  < 8 ) {
greeting = "Congratulations! You've got FREE GIFT";
} else if (time < 19) {
greeting = "Congratulations! Yodsuh45d've got FREE GIFT";
} else {
greeting = "Congratulations!";
}
document.getElementById("freeGift").innerHTML = greeting;
</script>

"quot">

我正在寻求意见并帮助执行它。

最新更新