问题
Coding noob here.
I give up. Been trying to this on my own for a week. I can't display the stock level on my product page (based on inventory). I'm using the theme "Debut". I saw this and this, but can't make things happen. Any help would be very much appreciated!!
回答1:
Debut does not have selectCallback. If you use another template, like Launchpad-Star, the instructions work perfectly.
1) Edit the product in question and be sure Inventory policy is set to "Shopify tracks this product's inventory." Make sure the checkbox "Allow customers to purchase this product when it's out of stock" is unset.
2) In Admin, click "View your online store." Then click the Customize Theme button. Then click the button with elipses and select "Edit Code."
3) Go to Sections->product_template.liquid
4) Paste in the code from step 4 in https://help.shopify.com/themes/customization/products/show-inventory-quantities. I pasted it above form action="/cart/add".
5) Make the change described in the next step (which is also numbered 4) to selectCallback.
And that works fine.
If you still want to use Debut, do steps 1-2 above, then navigate to Assets->theme.js, and paste in
if (variant.inventory_management == "shopify" && variant.inventory_policy != "continue") {
if (variant.inventory_quantity > 0) {
jQuery('#variant-inventory').text(' ' + variant.inventory_quantity + ' left in stock.');
}
else {
jQuery('#variant-inventory').text("This product is sold out");
}
} else {
jQuery('#variant-inventory').text("This product is available");
}
You want to do this in _onSelectChange: function around line 534 (below the return on !variant.)
来源:https://stackoverflow.com/questions/43801458/shopify-how-to-show-stock-level-on-product-page