10亿+海关交易数据,1.2亿企业数据,2亿+企业联系人数据,1000千万真实采购商。覆盖200+个国家及地区,95%外贸重点拓展市场,可根据行业、经营范围等多方位挖掘目标客户。
免费试用在产品页面上显示剩余的多属性库存
您可以在产品页面或特色产品分区中添加一条消息,用于在产品多属性库存较低时显示库存中的商品数量。若要显示此消息,您需要为产品启用库存跟踪。
此自定义设置的步骤因您的模板而异。点击模板的按钮,然后按照说明操作。
提示:Shopify 的 Supply 模板中已包含显示剩余数量消息设置。您可以在模板辑器中启用此设置。
Debut
Venture / Brooklyn / Simple / Minimal
Boundless
Narrative
theme.liquid
在 Shopify 后台中,转到在线商店 > 模板。
找到要编辑的模板,然后点击操作 > 编辑代码。
在 Layout 目录中,打开 theme.liquid
。
查找代码中的结束 </head>
标记。在结束 </head>
标记上方的新行中,粘贴以下代码:
<script> var variantStock = {}; </script>
点击保存。
product-template.liquid
或 featured-product.liquid
在 Sections 目录中,打开 product-template.liquid
或 featured-product.liquid
:
打开 product-template.liquid
以将此功能添加到产品页面。
打开 featured-product.liquid
以将此功能添加到主页上的特色产品分区。
查找 {% form 'product'
。在此标记上方添加以下代码:
<div> {% if current_variant.inventory_quantity > 0 and current_variant.inventory_management == 'shopify' %} <p>Stock: {{ current_variant.inventory_quantity }}</p> {% endif %} </div>
上述代码会输出 Stock: x
。您可以通过调整 <p>
标记中的内容来更改措辞。请确保在 <p>
标记中包含 {{ current_variant.inventory_quantity }}
。
在文件底部,添加以下代码:
<script> {% for variant in product.variants %} variantStock[{{- variant.id -}}] = {{ variant.inventory_quantity }}; {% endfor %} </script>
点击保存。
theme.js.liquid
或 theme.js
您需要对这些文件所做的更改取决于您使用的 Debut 版本。
打开 theme.js.liquid
或 theme.js
。
查找 theme.Product = (function()
。在 this.selectors = {
下方添加以下代码:
inventoryHtml: '.inventoryWrapper',
在同一文件中,查找 _updateAddToCart: function(evt) {
。在正下方添加以下代码:
var inventoryWrapper = this.container.querySelector(this.selectors.inventoryHtml);
查找 if (variant.available) {
。在 } else {
语句前添加以下代码:js if (variantStock[variant.id] > 0 && variant.inventory_management == 'shopify' && inventoryWrapper !== null) { const inventoryHtml =
Stock: ${variantStock[variant.id]}
; inventoryWrapper.innerHTML = inventoryHtml; } else { inventoryWrapper.innerHTML = ''; }
上述代码会输出 Stock: x
。您可以通过调整 <p>
标记中的内容来更改措辞。请确保在 <p>
标记中包含 ${variantStock[variant.id]}
。
点击保存。
打开 theme.js.liquid
或 theme.js
。
查找 theme.Product = (function()
。在 this.selectors = {
下方添加以下代码:
inventoryHtml: '.inventoryWrapper',
在同一文件中,查找 _setProductState: function(evt) {
。在正下方添加以下代码:
var inventoryWrapper = this.container.querySelector(this.selectors.inventoryHtml);
在同一函数中,查找 if (!variant) {
。在右 }
括号后,添加以下代码:
else { if (variantStock[variant.id] > 0 && variant.inventory_management == 'shopify' && inventoryWrapper !== null) { const inventoryHtml = `<p>Stock: ${variantStock[variant.id]}</p>`; inventoryWrapper.innerHTML = inventoryHtml; } else { inventoryWrapper.innerHTML = ''; } }
上述代码会输出 Stock: x
。您可以通过调整 <p>
标记中的内容来更改措辞。请确保在 <p>
标记中包含 ${variantStock[variant.id]}
。
点击保存。
Shopify商户官网原文详情:
Show the remaining inventory of a variant on product pages
You can add a message on the product page or featured product section that shows the number of items you have in stock when inventory runs low on a product variant. For this message to show, you need to enable inventory tracking for the product.
The steps for this customization vary depending on your theme. Click the button for your theme and follow the instructions.
Debut
Venture / Brooklyn / Simple / Minimal
Boundless
Narrative
Steps for Debut
Edit
theme.liquid
From your Shopify admin, go to Online Store > Themes.
Find the theme you want to edit, and then click Actions > Edit code.
From the Layout directory, open
theme.liquid
.Find the closing
</head>
tag in the code. On a new line above the closing</head>
tag, paste the following code:<script> var variantStock = {}; </script>Click Save.
Edit
product-template.liquid
orfeatured-product.liquid
From the Sections directory, open
product-template.liquid
orfeatured-product.liquid
:
Open
product-template.liquid
to add this feature to product pages.Open
featured-product.liquid
to add this feature to the featured product section on the home page.Find
{% form 'product'
. Above this tag, add the following code:<div> {% if current_variant.inventory_quantity > 0 and current_variant.inventory_management == 'shopify' %} <p>Stock: {{ current_variant.inventory_quantity }}</p> {% endif %} </div>The code above outputs
Stock: x
. You can change the wording by adjusting the content in the<p>
tags. Make sure to include{{ current_variant.inventory_quantity }}
in your<p>
tags.At the bottom of the file, add the following code:
<script> {% for variant in product.variants %} variantStock[{{- variant.id -}}] = {{ variant.inventory_quantity }}; {% endfor %} </script>Click Save.
Edit
theme.js.liquid
ortheme.js
The changes that you need to make to these files depend on the version of Debut that you're using.
Versions 17.8.0 and below
Open
theme.js.liquid
ortheme.js
.Find
theme.Product = (function()
. Belowthis.selectors = {
, add the following code:inventoryHtml: '.inventoryWrapper',In the same file, find
_updateAddToCart: function(evt) {
. Directly below, add the following code:var inventoryWrapper = this.container.querySelector(this.selectors.inventoryHtml);Find
if (variant.available) {
. Before the} else {
statement, add the following code:js if (variantStock[variant.id] > 0 && variant.inventory_management == 'shopify' && inventoryWrapper !== null) { const inventoryHtml = `<p>Stock: ${variantStock[variant.id]}</p>`; inventoryWrapper.innerHTML = inventoryHtml; } else { inventoryWrapper.innerHTML = ''; }
The code above outputs
Stock: x
. You can change the wording by adjusting the content in the<p>
tags. Make sure to include${variantStock[variant.id]}
in your<p>
tags.Click Save.
Versions 17.9.0 and above
Open
theme.js.liquid
ortheme.js
.Find
theme.Product = (function()
. Belowthis.selectors = {
, add the following code:inventoryHtml: '.inventoryWrapper',In the same file, find
_setProductState: function(evt) {
. Directly below, add the following code:var inventoryWrapper = this.container.querySelector(this.selectors.inventoryHtml);In the same function, find
if (!variant) {
. After the closing}
bracket, add the following code:else { if (variantStock[variant.id] > 0 && variant.inventory_management == 'shopify' && inventoryWrapper !== null) { const inventoryHtml = `<p>Stock: ${variantStock[variant.id]}</p>`; inventoryWrapper.innerHTML = inventoryHtml; } else { inventoryWrapper.innerHTML = ''; } }The code above outputs
Stock: x
. You can change the wording by adjusting the content in the<p>
tags. Make sure to include${variantStock[variant.id]}
in your<p>
tags.Click Save.
文章内容来源:Shopify商户官方网站
(本文内容根据网络资料整理和来自用户投稿,出于传递更多信息之目的,不代表本站其观点和立场。本站不具备任何原创保护和所有权,也不对其真实性、可靠性承担任何法律责任,特此声明!)
在Shopify商城的产品页面上,你可以通过设置每个属性的库存数量,来显示不同属性组合下的剩余库存数量。具体操作如下:
不同属性值如何影响库存?Shopify支持为每个属性值设置单独的库存数量。当客户选择某个属性值时,产品库存就根据已选择属性值的库存进行动态更新显示。例如选择红色时库存显示100件,选择蓝色时库存显示50件。
多属性产品库存如何计算?对于有多个属性的产品,Shopify会把每个属性值的库存相乘,来计算不同属性组合下的剩余库存。例如尺码S颜色红库存100件,尺码S颜色蓝库存50件,那么尺码S颜色红的库存就是100件,尺码S颜色蓝的库存就是50件。
属性组合库存不足时如何提示?当用户选择的属性组合库存不足时,Shopify会自动在产品页面提示\"唯一可选择属性组合\"。此时也可以使用JavaScript操作DOM元素,自定义提示内容和样式。