在Shopify ../cart页面中将强制性协议绑定到多个产品 [英] Tying mandatory agreement in Shopify ../cart page to multiple products

查看:85
本文介绍了在Shopify ../cart页面中将强制性协议绑定到多个产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的Shopify购物车页面上添加了强制性确认,当我进行某些产品的预售时会显示该信息.

I've added a mandatory acknowledgment to my Shopify cart page that is displayed when I'm running pre-order sales for certain products.

{% 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标签的产品时,复选框协议才会显示.

The checkbox agreement will only show up if there is a product with a DECEMBER tag in the cart.

每种产品都适用于一种产品,但是我想使它适用于包含一个以上带有DECEMBER标签的产品的购物车.

Everything works great for one product, but I would like to get it working for a cart that contains more than one product with the DECEMBER tag.

例如,如果有三种带有DECEMBER标签的产品,我希望标签文字显示为即使产品,Product2和Product3可能不发货,我也承认公司名称将在结帐时从我的信用卡中扣除直到十二月.

For example, if there were three different products with the DECEMBER tag, I would like the label text to read "I acknowledge that Company Name will charge my credit card at checkout, even though the Product and Product2 and Product3 may not ship until December.

设置此设置的最佳方法是什么?

What would be the best way to set this up?

谢谢!

推荐答案

我会这样处理问题:

{% 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 %}

  1. 遍历购物车中的所有物品,如果产品带有标签"DECEMBER",则将其附加到带有分隔符的字符串中(例如"|").

  1. Loop through all the items in the cart, and if the product has the tag 'DECEMBER' append it to a string with a separator (e.g. '|').

然后,如果至少有一个预购产品,请使用 split join 格式化要输出的字符串.这很容易摆脱尾随的分隔符,并避免显示"Product1,&Products2,&Products3,&Products3"这样的输出.

Then if there is at least one pre-order product, use split and join to format the string for output. This is handy to get rid of the trailing separator and avoid output like "Product1, Product2, Product3, ".

这篇关于在Shopify ../cart页面中将强制性协议绑定到多个产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆