How let user enter discount code and create URL for user

How let user enter discount code and create URL for user

NewtoAllThis
Tourist
8 0 1

Need to add a code snipet to this page

https://morningragecoffee.com/pages/ehrs-band-fundraiser

 

With a text box to enter a discount code - then press a button to be redirected to the URL with that entered discount code embedded, like this:

 

https://morningragecoffee.com/discount/ERHS24001

 

Thanks in advance

 

Reply 1 (1)

PaulNewton
Shopify Partner
7640 671 1603

Hi @NewtoAllThis  👋 roughly use a custom-liquid section or block; assuming an OS2.0 theme

And some code like this UNTESTED code:

<script>
function redirectToDiscountURL(){
  var discountCode=document.getElementById("discountCode").value;
  var url="https://website.com/discount/"+discountCode;
  window.location.href=url;
}
</script>
<input type="text" id="discountCode" placeholder="Enter discount code" />
<button onclick="redirectToDiscountURL()">Apply Discount</button>

 Good luck.

 

If you need it further customized such as to be conditional or to use routes etc then contact me for services.
Contact info in forum signature.
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail in ALL correspondence.

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org