We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Problem with custom code

Problem with custom code

TrendBlend
Trailblazer
367 0 40

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: 

 

762C7D3D-9E22-466F-A83E-41AD44A9A390.png

 

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

Replies 4 (4)

BSSCommerce-B2B
Shopify Partner
1972 564 567

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

BSSCommerceB2B_0-1722929023200.png

If it helps you, please like and mark it as the solution.

Best Regards

 

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

BSSCommerce-B2B
Shopify Partner
1972 564 567

 

I hope these instructions will help you.

Have a nice day sir!

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

TrendBlend
Trailblazer
367 0 40

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?

BSSCommerce-B2B
Shopify Partner
1972 564 567

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

 

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now