

若要为配送日期选择器创建代码片段,请执行以下操作:
若要为配送日期选择器创建代码片段,请执行以下操作:
PC:
在 后台中,转到在线商店 > 模板。
找到要编辑的模板,然后点击操作 > 编辑代码。
在 Snippets 目录中,点击添加新代码片段。
创建代码片段:
将代码片段命名为 delivery-date
。
点击创建代码片段。新的代码片段文件将在代码编辑器中打开。
苹果系统:
在 Shopify 后台中,转到 > 模板。
找到要编辑的模板,然后点击操作 > 编辑代码。
在 Snippets 目录中,点击添加新代码片段。
创建代码片段:
将代码片段命名为 delivery-date
。
点击创建代码片段。新的代码片段文件将在代码编辑器中打开。
安卓系统:
在 Shopify 后台中,转到在线商店 > 模板。
找到要编辑的模板,然后点击操作 > 编辑代码。
在 Snippets 目录中,点击添加新代码片段。
创建代码片段:
将代码片段命名为 delivery-date
。
点击创建代码片段。新的代码片段文件将在代码编辑器中打开。
在新的 delivery-date.liquid
代码片段中,粘贴以下代码:
```html {{ '//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css' | stylesheet_tag }}
<div > <p> <label fo>Pick a delivery date:</label> <input type="text" name="attributes[date]" value="{{ cart.attributes.date }}" /> <span > We do not deliver during the week-end.</span> </p> </div> <script> window.onload = function() { if (window.jQuery) { let $ = window.jQuery; $(function() { $("#date").datepicker({ minDate: +1, maxDate: '+2M', beforeShowDay: $.datepicker.noWeekends }); }); } } </script>
1. 点击**保存**。 ## 在购物车页面中包含代码片段 若要在购物车页面中包含配送日期代码片段,请执行以下操作: 1. 在 **Sections** 目录中,点击 `cart-template.liquid`。如果您的模板中没有此文件,则点击 **Templates** 目录中的 `cart.liquid`。 2. [查找](/manual/shopify-admin/productivity-tools/keyboard-shortcuts#find)代码中的结束 `</form>` 标记。在结束 `</form>` 标记上方的新行中,粘贴以下代码: ```liquid {% render 'delivery-date' %}
点击保存。
您的购物车页面中现在将有一个配送日期输入字段。当您点击文本字段时,将出现日历:
此自定义设置中使用的日期选择器是 jQuery UI 库中的小组件。此博客文章介绍如何在日期选择器日历中禁用特定日期。
Create a delivery date snippet
To create a snippet for your delivery date picker:
PC:
From your Shopify admin, go to Online Store > Themes.
Find the theme you want to edit, and then click Actions > Edit code.
In the Snippets directory, click Add a new snippet:
Create the snippet:
Name your snippet
delivery-date
.Click Create snippet. The new snippet file will open in the editor.
iPhone:
From your Shopify admin, go to Online Store > Themes.
Find the theme you want to edit, and then click Actions > Edit code.
In the Snippets directory, click Add a new snippet:
Create the snippet:
Name your snippet
delivery-date
.Click Create snippet. The new snippet file will open in the code editor.
Android:
From your Shopify admin, go to Online Store > Themes.
Find the theme you want to edit, and then click Actions > Edit code.
In the Snippets directory, click Add a new snippet:
Create the snippet:
Name your snippet
delivery-date
.Click Create snippet. The new snippet file will open in the code editor.
In your new
delivery-date.liquid
snippet, paste the following code:{{ '//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" defe></script> <div > <p> <label fo>Pick a delivery date:</label> <input type="text" name="attributes[date]" value="{{ cart.attributes.date }}" /> <span > We do not deliver during the week-end.</span> </p> </div> <script> window.onload = function() { if (window.jQuery) { let $ = window.jQuery; $(function() { $("#date").datepicker({ minDate: +1, maxDate: '+2M', beforeShowDay: $.datepicker.noWeekends }); }); } } </script>Click Save.
Include the snippet in your cart page
To include the delivery date snippet in your cart page:
In the Sections directory, click
cart-template.liquid
. If your theme doesn't have this file, then clickcart.liquid
in the Templates directory.Find the closing
</form>
tag in the code. On a new line above the closing</form>
tag, paste the following code:{% render 'delivery-date' %}Click Save.
You now have a delivery date input field on your cart page. When you click inside the text field, a calendar will appear:
The date picker used in this customization is a widget from the jQuery UI library. This blog post explains how to disable specific dates in the date picker calendar.
特别声明:以上文章内容仅代表作者本人观点,不代表ESG跨境电商观点或立场。如有关于作品内容、版权或其它问题请于作品发表后的30日内与ESG跨境电商联系。
二维码加载中...
使用微信扫一扫登录
使用账号密码登录
平台顾问
微信扫一扫
马上联系在线顾问
小程序
ESG跨境小程序
手机入驻更便捷
返回顶部