Show stock message based on variant selection

Dear all,

I am looking for a solution to dynamically show a message on my product page, based on a variant stock level.

If I write this using only liquid code, the messages show up correctly when the page is loaded, but they are not dynamically updated after a new variant/option is selected. So I guess I need some more code to get the page updated like when the price changes when a variant is selected. Now it only works when manually refreshing the page after a variant selection.

Ideally I want to show one of the following messages, based on stock level:

  1. in stock — if stock is more than 10 units

  2. out of stock

  3. limited — if stock is between 0 and 10 units

I’m using the Empire theme.

Would be really thankful for any suggestions or further links to get more info.

Kind regards,

Jonas