Run Javascript post-purchase only

Topic summary

A user is trying to implement JavaScript that runs only after a successful purchase to clear Locksmith app session data.

The Problem:

  • Locksmith app locks the cart until customers enter a proof-of-purchase code (one-time use)
  • After purchase, Locksmith remembers the code during the session, allowing repeat purchases without a new code
  • Need to clear Locksmith parameters post-purchase to re-lock the cart

Current Challenges:

  • Cannot find “Additional scripts” section in Order status page (likely due to being on newer Shopify version)
  • Adding the script to theme.liquid partially works but causes issues: if customers enter code, add items to cart, then change their mind and empty cart to browse other products, the cart locks again even though they haven’t completed a purchase yet

What’s Needed:
Guidance on where to place the provided JavaScript snippet (which clears Locksmith cookies and parameters) so it executes only after successful purchase completion, not during browsing sessions.

Summarized with AI on November 4. AI used: claude-sonnet-4-5-20250929.

I’m looking for help on where to put some javascript so that it only runs after a successful purchase.

I have seen some suggestions like adding the javascript in the Additional scripts section in the Order status page, but I don’t see those options as I have just recently signed up to Shopify, so I think I’m on the latest Shopify which is slightly different?

To explain what I’m doing – I have set up the Locksmith app to lock the cart page until the customer puts in a proof of purchase code. Once they do this they can buy the product, but only one purchase for one code.

The issue, is that after the purchase, if they continue shopping, Locksmith remembers that they put in the code so the cart doesn’t lock after the purchase during the session, so he customer can buy again without putting in a new code.

That’s why I want to run the script, so it clears the locksmith parameters, thus locking the cart again.

However, adding the script to the theme.liquid file sort of works, but say a customer entered the code to access the cart, but before purchasing changed their mind, so emptied their cart and went back to the store to choose a different product and then adds it to the cart, then tries to go to the cart, but it’s locked again! Their code is one use only, so they can’t complete the purchase after changing their minds on what product to by – not ideal!

So again, I’m just looking for where to put the below script so it only runs post-purchase.

Here is the script:

Thanks in advance for any help!