向购物车页面添加配送日期选择器

您可以在购物车页面上包含一个日历,使客户能够指定其订单的配送日期。

配送日期选择器

警告:此自定义设置不适用于抽屉式或弹出式购物车,仅适用于购物车页面(位于 URL your-store.com/cart)。如果您使用购物车抽屉或弹出式购物车,您将需要在模板编辑器中将您的购物车样式更改为购物车页面。在模板预览中向购物车中添加产品,然后点击模板编辑器中的购物车页面选项卡,以查看您的购物车设置。

在 theme.liquid 中包含 jQuery

若要使此自定义正常工作,某些模板需要将 jQuery 的脚本标记添加到 theme.liquid 布局文件中。如果您使用 Boundless、Debut 版本 17.2.0 或更高版本、Express、Narrative 或 Venture,您可能需要按照如下步骤操作:

  1. Layout 目录中,点击 theme.liquid

  2. 查找代码中的结束 </head> 标记。在结束 </head> 标记上方的新行中,粘贴以下代码:

{{ '//ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js' | script_tag }}
  1. 点击保存

创建配送日期代码片段

桌面
  1. 在 Shopify 后台中,转至在线商店 > 模板

  2. 找到要编辑的模板,点击 ... 按钮打开操作菜单,然后点击编辑代码

  3. Snippets 目录中,点击添加新代码片段

  4. 创建代码片段:

    1. 将代码片段命名为 delivery-date
    2. 点击创建代码片段。新的代码片段文件将在代码编辑器中打开。
  5. 在新的 delivery-date.liquid 代码片段中,粘贴以下代码:

{{ '//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css' | stylesheet_tag }}
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" defer="defer"></script>

<div style="width:300px; clear:both;"> <p> <label for="date">Pick a delivery date:</label> <input id="date" type="text" name="attributes[date]" value="{{ cart.attributes.date }}" /> <span style="display:block" class="instructions"> We do not deliver during the week-end.</span> </p> </div>

<script> window.onload = function() { if (window.jQuery) { let $ = window.jQuery;

$(function() {
      $(&#x22;#date&#x22;).datepicker({
      minDate: +1,
      maxDate: &#x27;+2M&#x27;,
      beforeShowDay: $.datepicker.noWeekends
    });
  });
}

} </script>

  1. 点击保存
iPhone
  1. Shopify 应用中,点击 按钮。

  2. 销售渠道部分,点击在线商店

  3. 点击管理模板

  4. 找到要编辑的模板,点击 ... 按钮打开操作菜单,然后点击编辑代码

  5. Snippets 目录中,点击添加新代码片段

  6. 创建代码片段:

    1. 将代码片段命名为 delivery-date
    2. 点击创建代码片段。新的代码片段文件将在代码编辑器中打开。
  7. 在新的 delivery-date.liquid 代码片段中,粘贴以下代码:

{{ '//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css' | stylesheet_tag }}
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" defer="defer"></script>

<div style="width:300px; clear:both;"> <p> <label for="date">Pick a delivery date:</label> <input id="date" type="text" name="attributes[date]" value="{{ cart.attributes.date }}" /> <span style="display:block" class="instructions"> We do not deliver during the week-end.</span> </p> </div>

<script> window.onload = function() { if (window.jQuery) { let $ = window.jQuery;

$(function() {
      $(&#x22;#date&#x22;).datepicker({
      minDate: +1,
      maxDate: &#x27;+2M&#x27;,
      beforeShowDay: $.datepicker.noWeekends
    });
  });
}

} </script>

  1. 点击保存
Android
  1. Shopify 应用中,点击 按钮。

  2. 销售渠道部分,点击在线商店

  3. 点击管理模板

  4. 找到要编辑的模板,点击 ... 按钮打开操作菜单,然后点击编辑代码

  5. Snippets 目录中,点击添加新代码片段

  6. 创建代码片段:

    1. 将代码片段命名为 delivery-date
    2. 点击创建代码片段。新的代码片段文件将在代码编辑器中打开。
  7. 在新的 delivery-date.liquid 代码片段中,粘贴以下代码:

{{ '//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css' | stylesheet_tag }}
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" defer="defer"></script>

<div style="width:300px; clear:both;"> <p> <label for="date">Pick a delivery date:</label> <input id="date" type="text" name="attributes[date]" value="{{ cart.attributes.date }}" /> <span style="display:block" class="instructions"> We do not deliver during the week-end.</span> </p> </div>

<script> window.onload = function() { if (window.jQuery) { let $ = window.jQuery;

$(function() {
      $(&#x22;#date&#x22;).datepicker({
      minDate: +1,
      maxDate: &#x27;+2M&#x27;,
      beforeShowDay: $.datepicker.noWeekends
    });
  });
}

} </script>

  1. 点击保存

在购物车页面中包含代码片段

若要在购物车页面中包含配送日期代码片段,请执行以下操作:

  1. Sections 目录中,点击 cart-template.liquid。如果您的模板中没有此文件,则点击 Templates 目录中的 cart.liquid

  2. 查找代码中的结束 </form> 标记。在结束 </form> 标记上方的新行中,粘贴以下代码:

{% render 'delivery-date' %}
  1. 点击保存

您的购物车页面中现在将有一个配送日期输入字段。当您点击文本字段时,将出现日历:

配送日期选择器

此自定义设置中使用的日期选择器是 jQuery UI 库中的小组件。此博客文章介绍如何在日期选择器日历中禁用特定日期。

没有找到您需要的答案?我们将为您提供帮助。