I guess you did not understand me correctly.
There are three types of products in my store:
1. In stock (everything is ok, the left in stock quantity is show)
2. 0 items in stock (I would need message with lead time appeared here as items can be ordered from supplier)
3. Sold out (everything is ok, sold out means that supplier do not have it in their warehouse either (it could not be ordered at this time))
Hope you understand what I have in mind.
Thank you for your time.
Brian's code is correct, but yeah there's some evaluation conflict taking place. Make sure you duplicate your theme before making any changes. This edit requires you change the theme.js.liquid file -- which you CANNOT revert to an older version of. So if something gets screwed up, you'll need a separate backup theme to pull your working file from. I'd also suggest saving you theme.js.liquid in a notepad document.
After backing up, open your theme.js.liquid file on your non-live theme and locate the following code:
if (variant.inventory_management) { // Show how many items are left, if below 10 if (variant.inventory_quantity < 10 && variant.inventory_quantity >= 0 && this.settings.stockSetting == 'true') { this.settings.selectors.$variantQuantityMessage.html(theme.strings.product.only_left.replace('1', "Hello")); this.settings.selectors.$variantQuantity.addClass('is-visible'); } }
Replace that code with this:
if (variant.inventory_management) { // Show how many items are left, if below 10 if (variant.inventory_quantity < 10 && variant.inventory_quantity >= 0 && this.settings.stockSetting == 'true') { if (variant.inventory_quantity == 0){ this.settings.selectors.$variantQuantity.addClass('is-visible'); }else{ this.settings.selectors.$variantQuantityMessage.html(theme.strings.product.only_left.replace('1', variant.inventory_quantity)); this.settings.selectors.$variantQuantity.addClass('is-visible'); } } }
Preview that theme and test it. Check all your other products to be sure everything is working the way you want it before you make this live.
Everything working like a treat if product is without.
But if product has more than one variant the message says that all variants are in stock.
As for example lets take this product. (Silver one is not in stock, all other variants are in stock)
If I choose Black, and then Silver, it says that it is in stock.
But if I refresh the browser, Silver is shown with lead time.
I remember I had the same issue with inventory qty in Minimal theme when there is different qties in stock for different product variants.
Hope you understand what I mean.
This is an accepted solution.
Replace my previous code with this, didn't anticipate a selector changing it:
if (variant.inventory_management) { // Show how many items are left, if below 10 if (variant.inventory_quantity < 10 && variant.inventory_quantity >= 0 && this.settings.stockSetting == 'true') { if (variant.inventory_quantity == 0){ let alert = '<span id="variantQuantity-product-template__message">Item available from a supplier. Allow 2-3 weeks to deliver.</span>' this.settings.selectors.$variantQuantityMessage.html(alert); this.settings.selectors.$variantQuantity.addClass('is-visible'); }else{ this.settings.selectors.$variantQuantityMessage.html(theme.strings.product.only_left.replace('1', variant.inventory_quantity)); this.settings.selectors.$variantQuantity.addClass('is-visible'); console.log('goodbye'); } } }
@Ninthony many thanks! Works great now.
Please message me or leave your PayPal here, I will drop you few dollars for the help :-)
Cheers
User | Count |
---|---|
818 | |
130 | |
83 | |
78 | |
73 |