Custom message when there is 0 items in stock [Supply theme]

Solved
New Member
12 0 0

Yes, of course.

 

Here you go.

0 Likes
Shopify Partner
1535 209 568

Can't find a sold out product, any chance you can provide that link?

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
New Member
12 0 0

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.

0 Likes
Shopify Partner
1535 209 568

Ok well can you link me to a product that has 0 items in stock, I can't find one.

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
New Member
12 0 0

Sure.

 

Here you go.

0 Likes
Shopify Partner
1535 209 568

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. 

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
New Member
12 0 0

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.

0 Likes
Shopify Partner
1535 209 568

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');
              }
            }
          }

 

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
New Member
12 0 0

@Ninthony many thanks! Works great now.

 

Please message me or leave your PayPal here, I will drop you few dollars for the help :-)

 

Cheers

0 Likes
Shopify Partner
1535 209 568

I messaged you with my PayPal, thank you -- I appreciate it.

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes