Auto Apply Coupons
M
Michael Walker
Could we please "auto apply" discount codes based on a URL parameter please?
It'd be great to automatically apply a 100% off coupon so that when someone loads the page, they can see the discount applied, but they don't need to manually input the code.
This would be simple – you could use the same logic you use for the "query key" Custom Field forms, and the URL could look something like:
Thank you.
Log In
G
Guada Molina
This seems like a basic one!
S
Shelly Turner
Guada Molina To add the coupon into the field, add this at the end of your URL:
?coupon_code=YOURCODE
I have used this code to make it auto apply (so they do not have to click apply) and it seems to work. It delays the complete loading of checkout and then hits the apply. It waits 10 seconds to apply the code:
<script>
setTimeout(function(){
// Get the first element with class 'apply-coupon-btn' and click it
document.getElementsByClassName("apply-coupon-btn")[0].click();
}, 10000); // Wait 10 seconds before executing
</script>
J
Jacques Hopkins
Shelly Turner Is this still working for you?
I put the code exactly on the footer tracking of the page itself and it's not auto applying the coupon. I'm using the whole ?coupon_code=YOURCODE in the URL and the coupon code is in the field... it's just not getting auto applied.
T
Tony Barrett
This one seems pretty fundamental to me. Surely.
L
Lauren Scalf
Circling back to say this is still making me made this isn't a thing
L
Lauren Scalf
Why is this still not a thing 😭
T
Thomas Eder
Put this code in the footer of the funnel, it's some javascript that clicks the "apply coupon" button after the page has loaded.
<script>
setTimeout(function(){
// Get the first element with class 'apply-coupon-btn' and click it
document.getElementsByClassName("apply-coupon-btn")[0].click();
}, 3000); // Wait 3 seconds before executing
</script>
K
Kevin Libawski
Thomas Eder Legend ! Your script worked, the others here didnt! Thats the way to go guys! Does not work with 2step checkout though so I might have to seperate my checkout as a 2nd landingpage
J
Jacques Hopkins
Thomas Eder Is this still working for you?
I put the code exactly on the footer tracking of the page itself and it's not auto applying the coupon. I'm using the whole ?coupon_code=YOURCODE in the URL and the coupon code is in the field... it's just not getting auto applied.
J
John Elder
Any updates on this? Super useful...
D
Don Wilson
Any updates here? To convert our Shopify businesses over this is a basic need.
D
Don Wilson
Any update here? I've found workarounds that charge an extra $300 to setup, but this isn't ideal when apps like Clickfunnels and Shopify have this as a native functionality.
A
Anthony Llanos
Any updates?
S
Steve Day
definate bump to this - super useful for auto adding coupons to button links in campaigns so the client can see the real discount.
L
Lucas Garvin
Bump
M
Mike Valera
You can use the follow script: https://gist.github.com/mikevalera/bf9fbdd5b2682f07d9c209f78a252309
It will auto-apply any coupon that is passed via the URL like: https://yoursite.com?coupon_code=#####
Where ##### is your coupon
L
Lucas Garvin
Mike Valera Thanks for the contribution! Really great. Just FYI, this only works with 1-step checkout.
S
Steve Day
Mike Valera thanks for sharing. I tested this and it seems the customer still has to click the 'Apply Coupn' button for it to work. Just checking I've not done something wrong. thanks again
A
Avery Smith
Mike Valera you are the BOMB for sharing this. User still has to press "Apply" but better than nothing
A
Avery Smith
I actually gave the code to ChatGPT & told it the problem and it solved it
Increased Timeout: I increased the setTimeout delay from 500ms to 1000ms. This gives the page a bit more time to fully load the elements before the script tries to click the button. Sometimes elements take a bit longer to render, especially on slower connections or with complex pages.
Added focus(): I added applyCouponButton.focus(); before clicking the button. This ensures the button is in focus before the click event, which can sometimes help with triggering actions that rely on the element being actively focused.
<script>
document.addEventListener("DOMContentLoaded", function () {
function getQueryParam(param) {
var urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
var couponCode = getQueryParam("coupon_code");
if (couponCode) {
var couponInput = document.querySelector('input[name="coupon_code"]');
if (couponInput) {
couponInput.value = couponCode;
var inputEvent = new Event('input', { bubbles: true });
couponInput.dispatchEvent(inputEvent);
setTimeout(function () {
var applyCouponButton = document.querySelector('.apply-coupon-btn');
if (applyCouponButton) {
applyCouponButton.focus();
}
}, 1000); // Increased timeout
}
}
});
</script>
S
Santi Umaña
Avery Smith where do you add this?
M
Mustafa Salih Oğuz
Avery Smith I couldn't find where to add this as well
K
Kevin Libawski
Avery Smith any way this can be made functional with 2step checkout form? :(
Load More
→