我已经在我的Shopify购物车页面上添加了强制性确认,该页面在我为某些产品进行预订销售时显示。
{% for item in cart.items %}
{% if item.product.tags contains 'DECEMBER' %}
<div class="sixteen columns">
<p style="float:none; text-align:left; clear: both; margin: 10px 0;">
<input style="float:none; vertical-align:middle;" type="checkbox" id="agree" />
<label style="display:inline; float:none" for="agree">
<b>I acknowledge that Company Name will charge my credit card at checkout, even though the {{item.product.title}} may not ship until December.</b>
</label>
</p>
</div>
{% endif %}
{% endfor %}
<script>
$('[name="checkout"], input[name="goto_pp"], input[name="goto_gc"]').click(function() {
if($('#agree').is(':checked')){
$(this).submit();
}
else{
alert("You must agree with the Sales Terms to check out.");
return false;
}
});
</script>
只有购物车中有符合DECEMBER标签的商品时,才会显示复选框协议。
对于一种产品而言,一切都很有效,但我想让它适用于包含多个带有DECEMBER标签的产品的购物车。
例如,如果有三种不同的产品带有DECEMBER标签,我希望标签文字阅读&#34;我承认公司名称将在结帐时从我的信用卡中扣款,即使产品和产品2和产品3可能要到12月才能发货。
设置它的最佳方法是什么?
谢谢!
答案 0 :(得分:0)
我会像这样解决问题:
{% assign preorder = false %}
{% assign preorder_products = "" %}
{% for item in cart.items %}
{% if item.product.tags contains 'DECEMBER' %}
{% assign preorder = true %}
{% capture preorder_products %}{{ preorder_products | append: item.product.title | append: "|" }}{% endcapture %}
{% endif %}
{% endfor %}
{% if preorder %}
{% assign preorder_products = preorder_products | split: "|" | join: ", " %}
<div class="sixteen columns">
<p style="float:none; text-align:left; clear: both; margin: 10px 0;">
<input style="float:none; vertical-align:middle;" type="checkbox" id="agree" />
<label style="display:inline; float:none" for="agree">
<b>I acknowledge that Company Name will charge my credit card at checkout, even though the following products may not ship until December: {{ preorder_products }} </b>
</label>
</p>
</div>
{% endif %}