Shopify themes, liquid, logos, and UX
Hi,
I'd like to dynamically retrieve the current value of the quantity selector in a custom liquid code block.
That way, I can display a message stating the delivery time will be increased in case the entered quantity exceeds the current inventory.
My products are configure to allow the customer to exceed the avaialble inventory, and I'd like to keep it that way.
If not possible, any other way to achieve this?
Thanks!
Hi @rvdp88 ,
This is possible. Can you provide link to the store? I will provide the solution accordingly.
Thanks, but please provide the solution in here, so that everyone can see it.
We'd like to implement it ourselves.
Hi @rvdp88 ,
The code will defer from theme to theme. I have created code to work on DAWN theme. The following code will detect the quantity change. Dpo modify the code as per your requirement.
document.querySelector('[name="quantity"]').addEventListener('change', function(t){
document.querySelector('#message').innerHTML = `Your Quantity is ${t.target.value}`
})
Custom Liquid:
<p id="message"></p>
You can verify its working here https://mangit.myshopify.com/products/copy-of-adidas-mens-postmove-mid-basketball-shoes
Thanks a lot!
Where do I need to place the first code block exactly?
And second question:
In case I just wanted to have a variable {{ selectedQuantity }} available in the custom liquid code block, so that I can generate the message from there based on some checks, would that also be possible?
Hi @rvdp88 ,
That would be possible. We will have to add if condition as per our need to achieve this.
And the code needs to be added to the theme.liquid of the custom liquid section. The code should be wrapped inside <script></script>
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025