Hello, I’m trying to show random numbers for how many people have bought and seen the product in the last 24 hours. It currently works and shows like this:
But there is one problem, it disappears and when you switch variant and I don’t know how to fix this. I’m using dawn theme with the following code in main-products.liquid
code: https://codeshare.io/zl3m6N
webshop URL: https://trendblend.eu/products/controllable-led-curtain
Hi @TrendBlend ,
Because when you change variant productInfo will be rerendered and your custom is in product info will be dissapeared
Try call your custom code again at the end of function "renderProductInfo" . It’s in global.js file
If it helps you, please like and mark it as the solution.
Best Regards
I hope these instructions will help you.
Have a nice day sir!
Hello @BSSCommerce-B2B , thanks for the respond but the code that you editted in the codeshare still does not work when changing variant. I have this code for many products so it is a big part of code. Adding this under renderProductInfo would be adding like 1000 lines of code there, would you recommend that? Or is there maybe another way?
If your code it’s too big. Try add an event when you change your variant to call your fuction again.
document.querySelectorAll(".product-form__input select").forEach(selectElement => {
selectElement.addEventListener("change", function() {
setTimeout(()=>{
// Your function here
},2000)
});
});