第一次尝试这个。如果客户花费 200 美元或更多,我想将产品添加到客户的购物车。没有收到任何回应,想知道我做错了什么。此代码在 checkout.liquid
内<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
{% assign found_title = false %}
{% for item in checkout.line_items %}
{% if item.variant.id == 6564672929928 %}
{% assign found_title = true %}
{% endif %}
{% endfor %}
{% if checkout.subtotal_price > 20000 and found_title == false %}
<script>
$( document ).ready(function () {
variantId = 6564672929928
jQuery.post('/cart/add.js', {
items: [{
quantity: 1,
id: 6564672929928
}],
function(res){
console.log(res)
}
})
})
</script>
答案 0 :(得分:0)
请尝试以下代码:
$(function() {
var variantId = 6564672929928;
$.post('/cart/add.js', {
items: [{
quantity: 1,
id: variantId
}]
},
function(res) {
console.log(res)
}
});
});
在您的数据对象中,您未能关闭对象:
jQuery.post('/cart/add.js', {
这个被启动的对象从来没有被关闭过。