Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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:
<script>
window.addEventListener('load', () => {
document.cookie = "locksmith-params={}; path=/;";
$.post('/cart/update.json', { attributes: { locksmith: null } });
});
</script>
Thanks in advance for any help!
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025