shopifyÔÚ²úÆ·Ò³ÃæÉÏÏÔʾʣÓàµÄ¶àÊôÐÔ¿â´æ°ì·¨
ÔÚ²úÆ·Ò³ÃæÉÏÏÔʾʣÓàµÄ¶àÊôÐÔ¿â´æ
±¸×¢
ÈôÊÇÄúʹÓà Shopify µÄÃâ·ÑÄ£°å£¬£¬£¬£¬£¬£¬Äú¿ÉÒÔÁªÏµ Shopify Ö§³ÖÍŶӻñµÃ¹ØÓڴ˽̵̳Ä×ÊÖú¡£¡£¡£¡£¡£¡£¡£¡£´Ë½Ì³ÌÐèÒª 15 ·ÖÖÓµÄÉè¼ÆÊ±¼ä¡£¡£¡£¡£¡£¡£¡£¡£ÈôÒªÏàʶÏêÇ飬£¬£¬£¬£¬£¬Çë²ÎÔÄ Support for themes¡£¡£¡£¡£¡£¡£¡£¡£
±¸×¢
´Ë×Ô½ç˵ÓÃÓÚ¸´¹Å Shopify Ä£°å£¬£¬£¬£¬£¬£¬²»ÊÊÓÃÓÚ¡°Online Store 2.0¡±Ä£°å¡£¡£¡£¡£¡£¡£¡£¡£
ÕÒµ½ÄúµÄÄ£°å¼Ü¹¹°æ±¾
̽Ë÷¡°Online Store 2.0¡±Ä£°å×Ô½ç˵
Äú¿ÉÒÔÔÚ²úÆ·Ò³Ãæ»òÌØÉ«²úÆ··ÖÇøÖÐÌí¼ÓÒ»ÌõÐÂÎÅ£¬£¬£¬£¬£¬£¬ÓÃÓÚÔÚ²úÆ·¶àÊôÐÔ¿â´æ½ÏµÍʱÏÔʾ¿â´æÖеÄÉÌÆ·ÊýÄ¿¡£¡£¡£¡£¡£¡£¡£¡£ÈôÒªÏÔʾ´ËÐÂÎÅ£¬£¬£¬£¬£¬£¬ÄúÐèҪΪ²úÆ·ÆôÓÃ¿â´æ¸ú×Ù¡£¡£¡£¡£¡£¡£¡£¡£
´Ë×Ô½ç˵ÉèÖõİ취ÒòÄúµÄÄ£°å¶øÒì¡£¡£¡£¡£¡£¡£¡£¡£µã»÷Ä£°åµÄ°´Å¥£¬£¬£¬£¬£¬£¬È»ºóƾÌý˵Ã÷²Ù×÷¡£¡£¡£¡£¡£¡£¡£¡£
ÌáÐÑ£ºShopify µÄ Supply Ä£°åÖÐÒѰüÀ¨ÏÔʾʣÓàÊýÄ¿ÐÂÎÅÉèÖᣡ£¡£¡£¡£¡£¡£¡£Äú¿ÉÒÔÔÚÄ£°å¼Æ÷ÖÐÆôÓôËÉèÖᣡ£¡£¡£¡£¡£¡£¡£
Debut
Venture / Brooklyn / Simple / Minimal
Boundless
Narrative
Õë¶Ô Debut µÄ°ì·¨
±à¼ 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 °æ±¾¡£¡£¡£¡£¡£¡£¡£¡£
°æ±¾ 17.8.0 ¼°ÒÔÏÂ
·¿ª
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]}¡£¡£¡£¡£¡£¡£¡£¡£µã»÷ÉúÑÄ¡£¡£¡£¡£¡£¡£¡£¡£
°æ±¾ 17.9.0 ¼°ÒÔÉÏ
·¿ª
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
Note
If you use a free theme from Shopify, then you might be able to contact Shopify Support for help with this tutorial. It requires 15 minutes of design time. To learn more, refer to Support for themes.
Note
This customization is for vintage Shopify themes, and doesn't apply to Online Store 2.0 themes.
Find out your theme's architecture version
Explore Online Store 2.0 theme customizations
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.
Tip
Shopify¡¯s Supply theme already includes a Show remaining quantity message setting. You can enable this setting from the theme editor.
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.liquidorfeatured-product.liquid
From the Sections directory, open
product-template.liquidorfeatured-product.liquid:
Open
product-template.liquidto add this feature to product pages.Open
featured-product.liquidto 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.liquidortheme.jsThe 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.liquidortheme.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.liquidortheme.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ÉÌ»§¹Ù·½ÍøÕ¾
- 1ÔõÑùÓ¦¶ÔÃÀ¿Í¶àÈëפÌõ¼þÒªÔÂÁ÷Ë®30ÍòµÄÌôÕ½
- 2eBayÂô¼ÒÏëÖªµÀµÄ¿ªµêÓöÈÎÊÌâ
- 3Shopee¹Ù·½Ðû²¼£ºÏºÆ¤É̳ÇÉÌÆ·Éϼܹ淶¡ª¡ªÃÀ×±±£½¡ÀàÉÌÆ·ËµÃ÷
- 4¿ç¾³µçÉÌÊý¾ÝÆÊÎöµÄÊý¾Ý´¦Öóͷ£ºÍÆÊÎö
- 5Å·ÖÞÕ¾µÆ¾ßÂô¼ÒÑ¡Æ·×¢ÖØÊÂÏî
- 6ÖØÐ¿ªÉèϺƤµêËÁ£ºÀֳɵÄÕ½ÂԺͰ취
- 7ĦÂå¸ç¿ç¾³µçÉ̺Ã×öÂ𣿣¿£¿£¿£¿£¿£¿Êг¡Ô¶¾°ÔõÑù£¿£¿£¿£¿£¿£¿£¿
- 8¼ÓÄôó¶àÂ×¶àÍâÑó²ÖÔõôѡ£¡£¡£¡£¡£¡£¡£¡£¿£¿£¿£¿£¿£¿£¿
- 9µçÉÌÂô¼ÒÄê¶È±¨¸æÀï²»¿ÉºöÊÓµÄ18¸öÖ÷ÒªÖ¸±ê
- 10wishÏîÄ¿ÔËÓªÍÆ¹ã²ß»®¼Æ»®£º×½×¡WishÔËÓª¼Æ»®Èý´óÖØµã
- ´ó¼þÂô¼ÒרÏî½òÌùÑÓÉì2¸öÔ£¬£¬£¬£¬£¬£¬±¸»õ±¾Ç®Ö±½µ
- ÓÎÏ·³öº£Ð´Èë¡°Ê®ÎåÎ塱ÍýÏ룡
- 2026ÉîÛÚµç×Óչǰհ£º´æ´¢ÕǼ۵¹±Æ¹©Ó¦Á´Öع¹£¬£¬£¬£¬£¬£¬Ñº×¢AI¾ÍÄÜÂòͨÐÐÒµ¡°Èζ½¶þÂö¡±Â𣿣¿£¿£¿£¿£¿£¿
- ÐÂÊÖÈë¿Ú±¨¹Ø¼Æ»®
- Èë¿Úµ¥ÑöÃæ±¨¹ØÓëË«ÑöÃæ±¨¹ØÓÐÊ²Ã´Çø±ð
- »õÎïÈë¿Ú±¨¹ØÁ÷³ÌÓÐÄÄЩ
- СÎÒ˽¼ÒÎïÆ·Èë¿Ú±¨¹ØÖ¸ÄÏ
- ÔõÑùÖÎÀíÈë¿Ú±¨¹Ø
- Èë¿Ú±¨¼ìÈ«ÆÊÎö
- ´ò°çÈë¿ÚÇ幨±¨¹ØÁ÷³Ì¼°×¢ÖØÊÂÏî