Not able to apply discount in my shopify store

Topic summary

Main issue: A Shopify store’s custom JavaScript discount logic only applies a discount the first time a product is added to the side cart, and fails on subsequent additions.

Context: Implemented within a Shopify theme, tied to side cart behavior. Tags indicate JavaScript and theme-level customization.

Observed behavior: Discount is successfully applied on the initial add-to-cart event, but not on later cart updates or additional product additions. The user requests help to fix the logic so the discount persists/ reapplies reliably.

Artifacts: Three screenshots showing the code are provided; these images are central to understanding the implementation details and flow.

Technical terms: “Side cart” refers to an AJAX/slide-out cart interface in Shopify. Discount logic likely runs client-side via JavaScript.

Status: No answers or resolutions yet. Root cause, specific code issues, and required event handling or state management changes remain unidentified. The thread is open and seeking guidance on correcting the discount application behavior.

Summarized with AI on December 30. AI used: gpt-5.

I have written a code logic for applying discount codes in my shopify store which is given below

Help me fixing this code , the discount is applying only for first time i add product in cart (side cart)