退出
Shopify新手指南
1998人已读
1、本指南旨在帮助您打开思路、理清方向,顺利开启跨境之路。(持续更新中) 2、内容来源于各个公开渠道整理汇总,版权归原作者所有。 3、使用建议:可使用快捷键 Ctrl +D/Command +D 的形式收藏至浏览器,方便下次访问。
收藏(1248)
目录导航
Shopify 简介
定价计划
概述
初始设置
商店设计清单
聘请帮助人员
迁移到 Shopify
开始使用
注意事项
Shopify 后台
Shopify 后台概述
支持的浏览器
备份和复制
搜索 Shopify 后台
Shopify Mobile
生产力工具
Shopify 主页
时间表
合规性
确保您的商店符合 Shopify 的政策
版权
在美国 (US) 的 Shopify 上销售大麻二酚
隐私和安全
账户安全
隐私
您的账户
员工
登陆
管理账单
管理账户
暂停或停用商店
已冻结的 Shopify 商店
选择您的账户语言和地区
与 Shopify 合作伙伴合作
推荐创业家使用 Shopify
在线商店
设置
模板
菜单和链接
博客
动态结账按钮
图片
因假期关闭商店
Shopify Search & Discovery
搜索您的商店
速度
POS
开始使用 Shopify POS
通过 Shopify POS 当面销售
QuickBooks POS
B2B
B2B 设置清单
产品目录
公司
客户
支付条款
信用卡储存
结账和账户
草稿订单
测试 B2B 设置
B2B 模板代码
销售渠道
Facebook and Instagram by Meta
Google & YouTube
Shop
Linkpop
Buy Button
Shopify Collective
Faire 批发市场
TikTok Shop
批发
Shopify Marketplace Connect 应用
Shopify 结账
结账样式
结账表单选项
自定义和编辑结账页面
小费选项
设置地址收集偏好设置
订单处理流程
结账页面语言
商店政策
机器人保护
结账自定义项
测试订单
Script Editor 应用
产品
产品套装
添加产品
管理库存
购买选项
产品详细信息
数字产品
多属性
产品媒体
产品系列
销售礼品卡
导入和导出
搜索和筛选
为您的产品定价
Product Reviews
Handshake 批发市场
代发货
暂时更改您的产品线
产品分析概述
域名
添加域名
更改域名类型和目标
移除域名
管理域名的所有权
电子邮件托管和转发
管理域名设置
域名术语
对域名问题进行故障排除
收款
获得收款
Shop Pay
Shopify Payments
PayPal Express
Shop Cash
Shop Pay 分期付款
快捷结账
第三方提供商
其他付款方式
线下付款
支付授权和获取款项
拒付和查询
欺诈预防
Advanced Cash on Delivery
问题排查
地点
设置您的地点
将库存分配给各个地点
设置您的地点发货
发货和配送
Shopify 发货网络
了解运输
设置和管理您的发货和配送
Shopify Shipping
碳中和运输
发货和代发货服务
Shop Promise
客户
管理客户
客户账户
搜索客户资料
客户细分
导入和导出客户
从 MailChimp 导入
Bulk Account Inviter
提供在线客户服务
解决客户 CSV 文件错误
Shopify Flow
创建工作流
监视工作流
管理工作流
手动运行工作流
高级工作流
Shopify Flow 参考信息
订单
订单状态页面
发货
处理订单
创建草稿订单
管理订单
订单状态
导出为 CSV 文件
搜索、查看和打印订单
自助退货
Order Printer
创建退货和退款
管理订阅订单
编辑订单商品
入账付款
延期付款
取消、存档和删除订单
欺诈风险分析
恢复弃单
转化跟踪
通知
联系 Shopify 商店以了解订单
Fraud Filter
管理增加的销售额
订单分析概述
折扣
折扣类型
组合折扣
管理折扣码
导出折扣码
设置促销价格
弃单电子邮件
礼品卡折扣
销售渠道折扣
常见问题解答
Shopify Inbox
安装和访问 Shopify Inbox
管理客户对话
配置 Shopify Inbox
聊天设置和外观
对话指标
自定义数据
Metafields
元对象
访问选项
功能
复制到订单
营销和促销
制定营销计划
内容营销
管理您的品牌资产
改进SEO
Shopify 中的营销
Shopify Audiences
分析在线营销
远程购物体验
为季节性销售做准备
Shopify Collabs
限时抢购
像素代码和客户活动
分析
Shopify 分析
Google Analytics
ShopifyQL Notebooks
分析差异
应用
应用类型
查找应用
选择应用
安装应用
卸载应用
管理应用
获取应用帮助
不受支持的应用
应用权限和个人信息
对第三方应用的支持
Shopify Markets
管理市场
以当地货币定价
自动重定向
国际域名
本地化和翻译
关税和进口税
收款
运输和市场
使用 Markets 发布产品
Shopify Markets Pro
专家市场
聘请帮助人员
与专家合作
向专家付款
处理争议
完成工作
合作伙伴目录
聘请帮助人员
税费
一般税款设置步骤
基于地点的税费设置
基于登记的税费设置
Shopify Tax
美国税费
加拿大税费
欧盟税费
英国税费
Shopify POS 税费
数字产品税
手动税费和免税
运费税
关税和进口税
印度的 GST
Avalara AvaTax 提供的税务服务
日本税费
Data Exporter
德国的 TSE 合规
税务报告
组织设置
访问“组织设置”
管理用户
账单
用户安全
管理商店
组织分析
Shopify Plus Academy
自定义购物体验
自定义购物体验
资金
财务概述
Shopify Balance
Shopify Capital
Shopify Credit
Shopify Bill Pay
添加快速订单列表

免费 Shopify 模板的版本 11.0.0 或更高版本中支持快速订单列表分区。如果您想在商店中添加“快速订单列表”分区,则可将商店模板更新为最新版本。

如果您不想更改或更新模板,则可以使用 Liquid 或 Javascript 向您的模板中添加代码,以在产品页面上显示“快速订单列表”分区。

在更新您的模板文件之前,请确保复制您的模板以创建备份副本。


拓展您的业务

这属于高级教程。如果您不擅长查阅和编辑模板代码,则您可以与开发人员合作或聘请 Shopify 专家。


添加 Liquid 快速订单列表代码

您可以将代码添加到您模板的以下文件中,以支持“快速订单列表”分区:

main-product.liquid 或等效文件 步骤: 在 Shopify 后台中,转至在线商店 > 模板。 找到要编辑的模板,点击 ... 按钮打开操作菜单,然后点击编辑代码。 打开要编辑的文件。 在文件底部创建新行,然后添加以下代码: {%#theme-check-disable%}{%-assignitems_in_cart=cart|line_items_for:product|sum:'quantity'-%}{%#theme-check-enable%}<div class="color-background-1 gradient"> <quick-order-list class="page-width" id="quick-order-list" data-id="{{section.id}}" > <form action="{{routes.cart_update_url}}" class="quick-order-list__contents critical-hidden" method="post" id="QuickOrderList" > <div class="quick-order-list__container" id="main-variant-items"> <div class="js-contents"> <table class="quick-order-list__table"> <caption class="visually-hidden"> Quick Order List </caption> <thead> <tr> <th class="caption-with-letter-spacing" scope="col">{%-ifproduct.has_only_default_variant-%}Product{%-else-%}Variant{%-endif-%}</th> <th class="large-up-hide right caption-with-letter-spacing" scope="col">{%-ifproduct.has_only_default_variant-%}Product subtotal{%-else-%}Variant total{%-endif-%}</th> <th class="quick-order-list__table-heading--wide small-hide medium-hide caption-with-letter-spacing" scope="col" > Quantity </th> <th class="quick-order-list__table-heading--wide small-hide medium-hide caption-with-letter-spacing" scope="col" > Price </th> <th class="small-hide medium-hide right caption-with-letter-spacing" scope="col">{%-ifproduct.has_only_default_variant-%}Product subtotal{%-else-%}Variant total{%-endif-%}</th> </tr> </thead> <tbody>{%-ifproduct.has_only_default_variant-%}{%#theme-check-disable%}{%assigncart_qty=cart|item_count_for_variant:product.selected_or_first_available_variant.id%}{%#theme-check-enable%}<tr class="variant-item" id="Variant-{{product.selected_or_first_available_variant.id}}" data-variant-id="{{product.selected_or_first_available_variant.id}}" data-cart-qty="{{cart_qty}}" > <td class="variant-item__inner"> <div class="variant-item__media"> <div class="variant-item__image-container gradient global-media-settings{%unlessproduct.featured_media%}variant-item__image-container--no-img{%endunless%}">{%ifproduct.featured_media%}{%-assignimg_height=43|divided_by:product.featured_media.aspect_ratio|ceil-%}{{product.featured_media|image_url:width:86|image_tag:loading:'lazy',fetchpriority:'low',decoding:'async',class:'variant-item__image',width:43,height:img_height,widths:'86',alt:product.featured_media.alt|escape}}{%endif%}</div> </div> <div class="small-hide medium-hide"> <span class="variant-item__name h4 break">{{product.title|escape}}</span>{%-ifproduct.sku-%}<span class="variant-item__sku break">{{product.selected_or_first_available_variant.sku|escape}}</span>{%-endif-%}</div> </td> <td class="variant-item__details large-up-hide"> <div class="variant-item__info"> <span class="variant-item__name h4 break">{{variant.title|escape}}</span>{%-ifproduct.selected_or_first_available_variant.sku-%}<span class="variant-item__sku break">{{product.selected_or_first_available_variant.sku|escape}}</span>{%-endif-%}</div>{%-assignitem_price=product.selected_or_first_available_variant.price|money-%}{%-ifproduct.selected_or_first_available_variant.compare_at_price-%}<dl class="variant-item__discounted-prices"> <dt class="visually-hidden"> Regular price </dt> <dd> <s class="variant-item__old-price price price--end">{{product.selected_or_first_available_variant.compare_at_price|money}}</s> </dd> <dt class="visually-hidden"> Sale price </dt> <dd class="price"> <span class="price">{{item_price}}/ea </span> </dd> </dl>{%-else-%}<span class="price">{{item_price}}/ea </span>{%-endif-%}{%-ifproduct.selected_or_first_available_variant.availableandproduct.selected_or_first_available_variant.unit_price_measurement-%}<div class="unit-price caption"> <span class="visually-hidden">Unit price</span>{{product.selected_or_first_available_variant.unit_price|money}}<span aria-hidden="true">/</span> <span class="visually-hidden">&nbsp;per&nbsp;</span>{%-ifproduct.selected_or_first_available_variant.unit_price_measurement.reference_value!=1-%}{{-product.selected_or_first_available_variant.unit_price_measurement.reference_value-}}{%-endif-%}{{product.selected_or_first_available_variant.unit_price_measurement.reference_unit}}</div>{%-endif-%}</td> <td class="variant-item__totals right large-up-hide">{%-render'loading-overlay'-%}{%comment%}TODO: enable theme-check once `line_items_for` is accepted as valid filter{%endcomment%}{%#theme-check-disable%}<span class="price">{{cart|line_items_for:product.selected_or_first_available_variant|sum:'original_line_price'|money}}</span>{%#theme-check-enable%}</td> <td class="variant-item__quantity"> <quantity-popover> <div class="variant-item__quantity-wrapper quantity-popover-wrapper variant-item__quantity-wrapper--no-info"> <label class="visually-hidden" for="Quantity-{{variant.id}}"> Quantity </label> <div class="quantity-popover-container">{%-ifproduct.selected_or_first_available_variant.available==false-%}<span class="variant-item__sold-out h4"> Sold out </span>{%-else-%}{%comment%}TODO: Remove theme check{%endcomment%}{%#theme-check-disable%}{%assigncart_qty=cart|item_count_for_variant:product.selected_or_first_available_variant.id%}{%#theme-check-enable%}{%render'quantity-input',variant:product.selected_or_first_available_variant%}{%-endif-%}</div>{%-ifcart_qty>0-%}<quick-order-list-remove-button id="Remove-{{product.selected_or_first_available_variant.id}}" data-index="{{product.selected_or_first_available_variant.id}}" > <a href="{{product.selected_or_first_available_variant.url_to_remove}}" class="button button--tertiary" aria-label="Remove{{variant.title}}" >{%render'icon-remove'%}</a> </quick-order-list-remove-button>{%-endif-%}</div> <div class="variant-item__error large-up-hide" id="Quick-order-list-item-error-mobile-{{product.selected_or_first_available_variant.id}}" role="alert" > <small class="variant-item__error-text"></small>{%render'icon-error'%}</div> </quantity-popover> </td>{%-assignitem_price=product.selected_or_first_available_variant.price|money-%}<td class="variant-item__price small-hide medium-hide">{%-ifvariant.compare_at_price-%}<dl class="variant-item__discounted-prices"> <dt class="visually-hidden"> Regular price </dt> <dd> <s class="variant-item__old-price price price--end">{{product.selected_or_first_available_variant.compare_at_price|money}}</s> </dd> <dt class="visually-hidden"> Sale price </dt> <dd class="price"> <span class="price">{{item_price}}/ea </span> </dd> </dl>{%-else-%}<span class="price">{{item_price}}/ea </span>{%-endif-%}{%-ifproduct.selected_or_first_available_variant.availableandproduct.selected_or_first_available_variant.unit_price_measurement-%}<div class="unit-price caption"> <span class="visually-hidden">Unit price</span>{{variant.unit_price|money}}<span aria-hidden="true">/</span> <span class="visually-hidden">&nbsp;per&nbsp;</span>{%-ifproduct.selected_or_first_available_variant.unit_price_measurement.reference_value!=1-%}{{-product.selected_or_first_available_variant.unit_price_measurement.reference_value-}}{%-endif-%}{{product.selected_or_first_available_variant.unit_price_measurement.reference_unit}}</div>{%-endif-%}</td> <td class="variant-item__totals right small-hide medium-hide">{%-render'loading-overlay'-%}{%comment%}TODO: enable theme-check once `line_items_for` is accepted as valid filter{%endcomment%}{%#theme-check-disable%}<span class="price">{{cart|line_items_for:product.selected_or_first_available_variant|sum:'original_line_price'|money}}</span>{%#theme-check-enable%}</td> </tr> <tr class="small-hide medium-hide hidden desktop-row-error"> <td></td> <td> <div class="variant-item__error" id="Quick-order-list-item-error-desktop-{{variant.id}}" role="alert"> <small class="variant-item__error-text"></small>{%render'icon-error'%}</div> </td> <td></td> <td></td> </tr>{%-else-%}{%-forvariantinproduct.variants-%}{%#theme-check-disable%}{%assigncart_qty=cart|item_count_for_variant:variant.id%}{%#theme-check-enable%}<tr class="variant-item" id="Variant-{{variant.id}}" data-variant-id="{{variant.id}}" data-cart-qty="{{cart_qty}}" > <td class="variant-item__inner"> <div class="variant-item__media"> <div class="variant-item__image-container gradient global-media-settings{%unlessvariant.image%}variant-item__image-container--no-img{%endunless%}">{%ifvariant.image%}{%-assignimg_height=43|divided_by:variant.image.aspect_ratio|ceil-%}{{variant.image|image_url:width:86|image_tag:loading:'lazy',fetchpriority:'low',decoding:'async',class:'variant-item__image',width:43,height:img_height,widths:'86',alt:variant.image.alt|escape}}{%endif%}</div> </div> <div class="small-hide medium-hide"> <span class="variant-item__name h4 break">{{variant.title|escape}}</span>{%-ifvariant.sku-%}<span class="variant-item__sku break">{{variant.sku|escape}}</span>{%-endif-%}</div> </td> <td class="variant-item__details large-up-hide"> <div class="variant-item__info"> <span class="variant-item__name h4 break">{{variant.title|escape}}</span>{%-ifvariant.sku-%}<span class="variant-item__sku break">{{variant.sku|escape}}</span>{%-endif-%}</div>{%-assignitem_price=variant.price|money-%}{%-ifvariant.compare_at_price-%}<dl class="variant-item__discounted-prices"> <dt class="visually-hidden"> Regular price </dt> <dd> <s class="variant-item__old-price price price--end">{{variant.compare_at_price|money}}</s> </dd> <dt class="visually-hidden"> Sale price </dt> <dd class="price"> <span class="price">{{item_price}}/ea </span> </dd> </dl>{%-else-%}<span class="price">{{item_price}}/ea </span>{%-endif-%}{%-ifvariant.availableandvariant.unit_price_measurement-%}<div class="unit-price caption"> <span class="visually-hidden">Unit price</span>{{variant.unit_price|money}}<span aria-hidden="true">/</span> <span class="visually-hidden">&nbsp;per&nbsp;</span>{%-ifvariant.unit_price_measurement.reference_value!=1-%}{{-variant.unit_price_measurement.reference_value-}}{%-endif-%}{{variant.unit_price_measurement.reference_unit}}</div>{%-endif-%}</td> <td class="variant-item__totals right large-up-hide">{%-render'loading-overlay'-%}{%comment%}TODO: enable theme-check once `line_items_for` is accepted as valid filter{%endcomment%}{%#theme-check-disable%}<span class="price">{{cart|line_items_for:variant|sum:'original_line_price'|money}}</span>{%#theme-check-enable%}</td> <td class="variant-item__quantity"> <quantity-popover> <div class="variant-item__quantity-wrapper quantity-popover-wrapper variant-item__quantity-wrapper--no-info"> <label class="visually-hidden" for="Quantity-{{variant.id}}"> Quantity </label> <div class="quantity-popover-container">{%-ifvariant.available==false-%}<span class="variant-item__sold-out h4">Sold out</span>{%-else-%}{%comment%}TODO: Remove theme check{%endcomment%}{%#theme-check-disable%}{%assigncart_qty=cart|item_count_for_variant:variant.id%}{%#theme-check-enable%}{%render'quantity-input',variant:variant%}{%-endif-%}</div>{%-ifcart_qty>0-%}<quick-order-list-remove-button id="Remove-{{variant.id}}" data-index="{{variant.id}}" > <a href="{{variant.url_to_remove}}" class="button button--tertiary" aria-label="Remove{{variant.title}}" >{%render'icon-remove'%}</a> </quick-order-list-remove-button>{%-endif-%}</div> <div class="variant-item__error large-up-hide" id="Quick-order-list-item-error-mobile-{{variant.id}}" role="alert" > <small class="variant-item__error-text"></small>{%render'icon-error'%}</div> </quantity-popover> </td>{%-assignitem_price=variant.price|money-%}<td class="variant-item__price small-hide medium-hide">{%-ifvariant.compare_at_price-%}<dl class="variant-item__discounted-prices"> <dt class="visually-hidden"> Regular price </dt> <dd> <s class="variant-item__old-price price price--end">{{variant.compare_at_price|money}}</s> </dd> <dt class="visually-hidden"> Sale price </dt> <dd class="price"> <span class="price">{{item_price}}/ea </span> </dd> </dl>{%-else-%}<span class="price">{{item_price}}/ea </span>{%-endif-%}{%-ifvariant.availableandvariant.unit_price_measurement-%}<div class="unit-price caption"> <span class="visually-hidden">Unit price</span>{{variant.unit_price|money}}<span aria-hidden="true">/</span> <span class="visually-hidden">&nbsp;per&nbsp;</span>{%-ifvariant.unit_price_measurement.reference_value!=1-%}{{-variant.unit_price_measurement.reference_value-}}{%-endif-%}{{variant.unit_price_measurement.reference_unit}}</div>{%-endif-%}</td> <td class="variant-item__totals right small-hide medium-hide">{%-render'loading-overlay'-%}{%comment%}TODO: enable theme-check once `line_items_for` is accepted as valid filter{%endcomment%}{%#theme-check-disable%}<span class="price">{{cart|line_items_for:variant|sum:'original_line_price'|money}}</span>{%#theme-check-enable%}</td> </tr> <tr class="small-hide medium-hide hidden desktop-row-error"> <td></td> <td> <div class="variant-item__error" id="Quick-order-list-item-error-desktop-{{variant.id}}" role="alert"> <small class="variant-item__error-text"></small>{%render'icon-error'%}</div> </td> <td></td> <td></td> </tr>{%-endfor-%}{%-endif-%}</tbody> </table> </div> <noscript>{%-ifproduct.has_only_default_variantorproduct.variants.size==1-%}<button type="submit" class="button button--secondary right" formnovalidate form="QuickOrderList"> Update </button>{%-endif-%}</noscript> </div> <p class="visually-hidden" id="quick-order-list-live-region-text" aria-live="polite" role="status"></p> <p class="visually-hidden" id="shopping-cart-variant-item-status" aria-live="polite" aria-hidden="true" role="status" > Loading... </p> </form>{%-ifproduct.has_only_default_variantorproduct.variants.size==1-%}<span class="quick-order-list-error">{%comment%}Populated by JS{%endcomment%}</span>{%-else-%}<div class="quick-order-list__total gradient" id="quick-order-list-total"> <div class="quick-order-list-total__info"> <div class="quick-order-list-total__column small-hide medium-hide"> <div class="quick-order-list-buttons"> <a href="{{routes.cart_url}}" class="quick-order-list__button button button--secondary small-hide medium-hide" > <span class="quick-order-list__button-text">View cart</span> </a> <div class="variant-remove-total">{%-render'loading-overlay'-%}<quick-order-list-remove-all-button class="no-js-hidden" data-action="confirm" > <button class="button button--tertiary" type="button">{%render'icon-remove'%}<span class="text-body">Remove all</span> </button> </quick-order-list-remove-all-button> </div> </div> <span class="quick-order-list__message caption-large" role="status"> <span class="quick-order-list__message-icon hidden">{%-render'icon-checkmark'-%}</span> <span class="quick-order-list__message-text"></span> </span> <span class="quick-order-list-error">{%comment%}Populated by JS{%endcomment%}</span> </div> <div class="quick-order-list__total-items"> <h3>{{items_in_cart}}</h3> <p class="h5">Total items</p> </div> <div class="quick-order-list-total__price"> <noscript> <button type="submit" class="button button--secondary" formnovalidate form="QuickOrderList"> Update </button> </noscript> <div class="totals__product-total"> <h3 class="totals__subtotal-value">{%comment%}TODO: enable theme-check once `line_items_for` is accepted as valid filter{%endcomment%}{%#theme-check-disable%}{{cart|line_items_for:product|sum:'original_line_price'|money}}{%#theme-check-enable%}</h3> <p class="totals__subtotal h5">Product subtotal</p> </div> <small class="tax-note caption-large rte">{%-ifcart.taxes_includedandshop.shipping_policy.body!=blank-%}Tax included. <a href="{{shop.shipping_policy.url}}">Shipping</a> and discounts calculated at checkout.{%-elsifcart.taxes_included-%}Tax included and shipping and discounts calculated at checkout{%-elsifshop.shipping_policy.body!=blank-%}Taxes, Discounts and <a href="{{shop.shipping_policy.url}}">shipping</a> calculated at checkout{%-else-%}Taxes, discounts and shipping calculated at checkout{%-endif-%}</small> </div> <div class="quick-order-list-total__column large-up-hide"> <div class="quick-order-list-buttons"> <a href="{{routes.cart_url}}" class="quick-order-list__button button button--secondary button--full-width" > <span class="quick-order-list__button-text">View cart</span> </a> <div class="variant-remove-total">{%-render'loading-overlay'-%}<quick-order-list-remove-all-button class="no-js-hidden" data-action="confirm" > <button class="button button--tertiary" type="button">{%render'icon-remove'%}<span class="text-body">Remove all</span> </button> </quick-order-list-remove-all-button> </div> </div> <span class="quick-order-list__message caption-large" role="status"> <span class="quick-order-list__message-icon hidden">{%-render'icon-checkmark'-%}</span> <span class="quick-order-list__message-text"></span> </span> <span class="quick-order-list-error">{%comment%}Populated by JS{%endcomment%}</span> </div> </div> <div class="quick-order-list-total__confirmation hidden"> <span class="text-body"> Remove all{{items_in_cart}}items from your cart? </span> <quick-order-list-remove-all-button data-action="remove" > <button class="quick-order-list__button-confirm button button--secondary" type="button" > Remove all </button> </quick-order-list-remove-all-button> <quick-order-list-remove-all-button data-action="cancel" > <button class="quick-order-list__button-cancel button button--tertiary" type="button" > Cancel </button> </quick-order-list-remove-all-button> </div> </div>{%-endif-%}</quick-order-list> <template id="QuickOrderListErrorTemplate-{{section.id}}">{%render'icon-error'%}<span class="quick-order-list-error-message caption-large" role="alert"></span> </template> </div> 点击保存。


添加 Javascript 快速订单列表代码

当多属性的购物车数量发生变化时,产品小计、多属性小计和可能出现的错误状态将会更新。可以使用 Javascript 代码获取更新后的值。

您可以向 theme.js 文件或等效文件中添加代码。

步骤:

在 Shopify 后台中,转至在线商店 > 模板。 找到要编辑的模板,点击 ... 按钮打开操作菜单,然后点击编辑代码。 打开 theme.js 文件。 在文件底部创建新行,然后添加以下代码: classQuickOrderListRemoveButtonextendsHTMLElement{constructor(){super();this.addEventListener('click',(event)=>{event.preventDefault();constquickOrderList=this.closest('quick-order-list');quickOrderList.updateQuantity(this.dataset.index,0);});}}customElements.define('quick-order-list-remove-button',QuickOrderListRemoveButton);classQuickOrderListRemoveAllButtonextendsHTMLElement{constructor(){super();constallVariants=Array.from(document.querySelectorAll('[data-variant-id]'));constitems={}lethasVariantsInCart=false;this.quickOrderList=this.closest('quick-order-list');allVariants.forEach((variant)=>{constcartQty=parseInt(variant.dataset.cartQty);if(cartQty>0){hasVariantsInCart=true;items[parseInt(variant.dataset.variantId)]=0;}});if(!hasVariantsInCart){this.classList.add('hidden');}this.actions={confirm:'confirm',remove:'remove',cancel:'cancel'}this.addEventListener('click',(event)=>{event.preventDefault();if(this.dataset.action===this.actions.confirm){this.toggleConfirmation(false,true);}elseif(this.dataset.action===this.actions.remove){this.quickOrderList.updateMultipleQty(items);this.toggleConfirmation(true,false);}elseif(this.dataset.action===this.actions.cancel){this.toggleConfirmation(true,false);}});}toggleConfirmation(showConfirmation,showInfo){this.quickOrderList.querySelector('.quick-order-list-total__confirmation').classList.toggle('hidden',showConfirmation);this.quickOrderList.querySelector('.quick-order-list-total__info').classList.toggle('hidden',showInfo)}}customElements.define('quick-order-list-remove-all-button',QuickOrderListRemoveAllButton);classQuickOrderListextendsHTMLElement{constructor(){super();this.cart=document.querySelector('cart-drawer');this.actions={add:'ADD',update:'UPDATE'}this.quickOrderListId='quick-order-list'this.variantItemStatusElement=document.getElementById('shopping-cart-variant-item-status');constform=this.querySelector('form');form.addEventListener('submit',this.onSubmit.bind(this));constdebouncedOnChange=debounce((event)=>{this.onChange(event);},ON_CHANGE_DEBOUNCE_TIMER);this.addEventListener('change',debouncedOnChange.bind(this));}cartUpdateUnsubscriber=undefined;onSubmit(event){event.preventDefault();}connectedCallback(){this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,(event)=>{if(event.source===this.quickOrderListId){return;}// If its another section that made the updatethis.onCartUpdate();});this.sectionId=this.dataset.id;}disconnectedCallback(){if(this.cartUpdateUnsubscriber){this.cartUpdateUnsubscriber();}}onChange(event){constinputValue=parseInt(event.target.value);constcartQuantity=parseInt(event.target.dataset.cartQuantity);constindex=event.target.dataset.index;constname=document.activeElement.getAttribute('name');constquantity=inputValue-cartQuantity;if(cartQuantity>0){this.updateQuantity(index,inputValue,name,this.actions.update);}else{this.updateQuantity(index,quantity,name,this.actions.add);}}onCartUpdate(){fetch(`${window.location.pathname}?section_id=${this.sectionId}`).then((response)=>response.text()).then((responseText)=>{consthtml=newDOMParser().parseFromString(responseText,'text/html');constsourceQty=html.querySelector(this.quickOrderListId);this.innerHTML=sourceQty.innerHTML;}).catch(e=>{console.error(e);});}getSectionsToRender(){return[{id:this.quickOrderListId,section:document.getElementById(this.quickOrderListId).dataset.id,selector:'.js-contents'},{id:'cart-icon-bubble',section:'cart-icon-bubble',selector:'.shopify-section'},{id:'quick-order-list-live-region-text',section:'cart-live-region-text',selector:'.shopify-section'},{id:'quick-order-list-total',section:document.getElementById(this.quickOrderListId).dataset.id,selector:'.quick-order-list__total'},{id:'CartDrawer',selector:'#CartDrawer',section:'cart-drawer'}];}renderSections(parsedState){this.getSectionsToRender().forEach((section=>{constsectionElement=document.getElementById(section.id);if(sectionElement&&sectionElement.parentElement&&sectionElement.parentElement.classList.contains('drawer')){parsedState.items.length>0?sectionElement.parentElement.classList.remove('is-empty'):sectionElement.parentElement.classList.add('is-empty');setTimeout(()=>{document.querySelector('#CartDrawer-Overlay').addEventListener('click',this.cart.close.bind(this.cart));});}constelementToReplace=sectionElement&&sectionElement.querySelector(section.selector)?sectionElement.querySelector(section.selector):sectionElement;if(elementToReplace){elementToReplace.innerHTML=this.getSectionInnerHTML(parsedState.sections[section.section],section.selector);}}));}updateMultipleQty(items){this.querySelector('.variant-remove-total .loading-overlay').classList.remove('hidden');constbody=JSON.stringify({updates:items,sections:this.getSectionsToRender().map((section)=>section.section),sections_url:window.location.pathname});this.updateMessage();this.setErrorMessage();fetch(`${routes.cart_update_url}`,{...fetchConfig(),...{body}}).then((response)=>{returnresponse.text();}).then((state)=>{constparsedState=JSON.parse(state);this.renderSections(parsedState);}).catch(()=>{this.setErrorMessage('There was an error while updating your cart. Please try again.');}).finally(()=>{this.querySelector('.variant-remove-total .loading-overlay').classList.add('hidden');});}updateQuantity(id,quantity,name,action){this.toggleLoading(id,true);letrouteUrl=routes.cart_change_url;letbody=JSON.stringify({quantity,id,sections:this.getSectionsToRender().map((section)=>section.section),sections_url:window.location.pathname});letfetchConfigType;if(action===this.actions.add){fetchConfigType='javascript';routeUrl=routes.cart_add_url;body=JSON.stringify({items:[{quantity:parseInt(quantity),id:parseInt(id)}],sections:this.getSectionsToRender().map((section)=>section.section),sections_url:window.location.pathname});}this.updateMessage();this.setErrorMessage();fetch(`${routeUrl}`,{...fetchConfig(fetchConfigType),...{body}}).then((response)=>{returnresponse.text();}).then((state)=>{constparsedState=JSON.parse(state);constquantityElement=document.getElementById(`Quantity-${id}`);constitems=document.querySelectorAll('.variant-item');if(parsedState.description||parsedState.errors){constvariantItem=document.querySelector(`[id^="Variant-${id}"] .variant-item__totals.small-hide .loading-overlay`);variantItem.classList.add('loading-overlay--error');this.resetQuantityInput(id,quantityElement);if(parsedState.errors){this.updateLiveRegions(id,parsedState.errors);}else{this.updateLiveRegions(id,parsedState.description);}return;}this.classList.toggle('is-empty',parsedState.item_count===0);this.renderSections(parsedState);lethasError=false;constcurrentItem=parsedState.items.find((item)=>item.variant_id===parseInt(id));constupdatedValue=currentItem?currentItem.quantity:undefined;if(updatedValue&&updatedValue!==quantity){this.updateError(updatedValue,id);hasError=true;}constvariantItem=document.getElementById(`Variant-${id}`);if(variantItem&&variantItem.querySelector(`[name="${name}"]`)){variantItem.querySelector(`[name="${name}"]`).focus();}publish(PUB_SUB_EVENTS.cartUpdate,{source:this.quickOrderListId,cartData:parsedState});if(hasError){this.updateMessage();}elseif(action===this.actions.add){this.updateMessage(parseInt(quantity))}elseif(action===this.actions.update){this.updateMessage(parseInt(quantity-quantityElement.dataset.cartQuantity))}else{this.updateMessage(-parseInt(quantityElement.dataset.cartQuantity))}}).catch((error)=>{this.querySelectorAll('.loading-overlay').forEach((overlay)=>overlay.classList.add('hidden'));this.resetQuantityInput(id);console.error(error);this.setErrorMessage('There was an error while updating your cart. Please try again.');}).finally(()=>{this.toggleLoading(id);});}resetQuantityInput(id,quantityElement){constinput=quantityElement??document.getElementById(`Quantity-${id}`);input.value=input.getAttribute('value');}setErrorMessage(message=null){this.errorMessageTemplate=this.errorMessageTemplate??document.getElementById(`QuickOrderListErrorTemplate-${this.sectionId}`).cloneNode(true);consterrorElements=document.querySelectorAll('.quick-order-list-error');errorElements.forEach((errorElement)=>{errorElement.innerHTML='';if(!message)return;constupdatedMessageElement=this.errorMessageTemplate.cloneNode(true);updatedMessageElement.content.querySelector('.quick-order-list-error-message').innerText=message;errorElement.appendChild(updatedMessageElement.content);});}updateMessage(quantity=null){constmessages=this.querySelectorAll('.quick-order-list__message-text');consticons=this.querySelectorAll('.quick-order-list__message-icon');if(quantity===null||isNaN(quantity)){messages.forEach(message=>message.innerHTML='');icons.forEach(icon=>icon.classList.add('hidden'));return;}constisQuantityNegative=quantity<0;constabsQuantity=Math.abs(quantity);consttextTemplate=isQuantityNegative?(absQuantity===1?`${absQuantity}item removed`:`${absQuantity}items removed`):(quantity===1?`${absQuantity}item added`:`${absQuantity}items added`)messages.forEach((msg)=>msg.innerHTML=textTemplate);if(!isQuantityNegative){icons.forEach((i)=>i.classList.remove('hidden'));}}updateError(updatedValue,id){letmessage='';if(typeofupdatedValue==='undefined'){message='There was an error while updating your cart. Please try again.';}else{message=`You can only add${updatedValue}of this item to your cart.`;}this.updateLiveRegions(id,message);}updateLiveRegions(id,message){constvariantItemErrorDesktop=document.getElementById(`Quick-order-list-item-error-desktop-${id}`);constvariantItemErrorMobile=document.getElementById(`Quick-order-list-item-error-mobile-${id}`);if(variantItemErrorDesktop){variantItemErrorDesktop.querySelector('.variant-item__error-text').innerHTML=message;variantItemErrorDesktop.closest('tr').classList.remove('hidden');}if(variantItemErrorMobile)variantItemErrorMobile.querySelector('.variant-item__error-text').innerHTML=message;this.variantItemStatusElement.setAttribute('aria-hidden',true);constcartStatus=document.getElementById('quick-order-list-live-region-text');cartStatus.setAttribute('aria-hidden',false);setTimeout(()=>{cartStatus.setAttribute('aria-hidden',true);},1000);}getSectionInnerHTML(html,selector){returnnewDOMParser().parseFromString(html,'text/html').querySelector(selector).innerHTML;}toggleLoading(id,enable){constquickOrderList=document.getElementById(this.quickOrderListId);constquickOrderListItems=this.querySelectorAll(`#Variant-${id}.loading-overlay`);if(enable){quickOrderList.classList.add('quick-order-list__container--disabled');[...quickOrderListItems].forEach((overlay)=>overlay.classList.remove('hidden'));document.activeElement.blur();this.variantItemStatusElement.setAttribute('aria-hidden',false);}else{quickOrderList.classList.remove('quick-order-list__container--disabled');quickOrderListItems.forEach((overlay)=>overlay.classList.add('hidden'));}}}customElements.define('quick-order-list',QuickOrderList); 点击保存。