Ecommerce software home
Shopping Cart Software Forum for Ecommerce Templates
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?



Find us on Facebook

Follow us on Twitter

View our YouTube channel


 All Forums
 Technical
 Advanced Tips and Tricks - NO QUESTIONS PLEASE
 Apply a coupon code from a URL (.asp version)
 New Topic  Reply to Topic
 Printer Friendly
Author  Topic   

dbdave
ECT Moderator

USA
8024 Posts

Posted - 09/09/2017 :  15:06:27  
I have seen this come up in suggestions before
"Can I apply a discount code from a link"?

Also, it's important, if you use discount codes, that you have a discounts page on your website. This serves several purposes.
Lots of coupon websites will harvest your codes and publish them. They send traffic to your site, and this is good, but they are promoting your competitors and harvesting old, no longer valid, codes.
Customers will also use a search engine to search for your company name - discounts or coupons. (ex - acme.com coupon codes)
It would much preferred to have your own discount codes page that shows current active codes and other savings you offer customers.
This page should eventually show better in the SE's than the other coupon codes sites.
Take control of your discount code destiny today

Step 1 (if you don't already have a discounts page)
Clone one of your pages and change the name of the page to something like websitename-discount-coupon-codes.asp
This needs to have all of the standard ect include lines, so you should clone a store page, products.asp for example.
Change the page title and meta description and clear the content area and create your new content.
You might like to list some codes that are currently active and have links to those products there.

Step 2
It would be great if visitors could actually type in a code right there, and not need to write it down and enter it during checkout.
Here we insert the javascript and .asp code that will duplicate the (checkout) coupon function on the page.

In the content area of the page, where you want the coupon input box to appear, add this
Take note there of the space where you will want to enter your URL of the page where you have placed this code. This is critical if you want to use step three (optional) and it causes no harm if you do not use step three.

<script type="text/javascript">
function applycertcallback(){
if(ajaxobj.readyState==4){
var retvals=ajaxobj.responseText.split('&');
alert(retvals[1]);
if(retvals[0]=='success'){document.getElementById("cpncode").value='';window.location.href = 'the-name-of-your-page-here.asp';}
}
}
function applycert(){
var cpncode=document.getElementById("cpncode").value;
if(cpncode!=""){
ajaxobj=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("MSXML2.XMLHTTP");
ajaxobj.onreadystatechange=applycertcallback;
ajaxobj.open("GET", "vsadmin/ajaxservice.asp?action=applycert&stg1=1&cpncode="+cpncode, true);
ajaxobj.send(null);
}
}
function removecert(cpncode){
if(cpncode!=''){
ajaxobj=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("MSXML2.XMLHTTP");
ajaxobj.onreadystatechange=applycertcallback;
ajaxobj.open("GET", "vsadmin/ajaxservice.asp?action=applycert&stg1=1&act=delete&cpncode="+cpncode, true);
ajaxobj.send(null);
}
}
</script>
<%
print "<div class=""cartcoupon_cntnr"">"
print "<div class=""cartcoupontext"">" & labeltxt(xxGifNum,"cpncode") & "</div>"
cpnarr=split(trim(SESSION("giftcerts")), " ")
for index=0 to UBOUND(cpnarr)
print "<div class=""cartcouponapplied"">" & imageorlink("",xxRemove&" : "&cpnarr(index),"applycoupon removecoupon1","removecert('"&cpnarr(index)&"')",TRUE) & "</div>"
next
cpnarr=split(trim(SESSION("cpncode")), " ")
for index=0 to UBOUND(cpnarr)
print "<div class=""cartcouponapplied"">" & imageorlink("",xxRemove&" : "&cpnarr(index),"applycoupon removecoupon1","removecert('"&cpnarr(index)&"')",TRUE) & "</div>"
next
print "<div class=""cartcoupon""><input type=""text"" name=""cpncode"" id=""cpncode"" size=""" & IIfVr(mobilebrowser,13,18) & """ style=""font-size:11px"" autocomplete=""off"" /> " & imageorbutton(imgapplycoupon,xxApply,"applycoupon applycoupon1","applycert()",TRUE) & "</div>"
print "</div>"
%>


Again, take note there of the space where you will want to enter your URL of the page where you have placed this code. This is critical if you want to use step three (optional) and it causes no harm if you do not use step three.

Step 3
Wouldn't it be really great to send a code in a link that would apply itself?
Have no fear....
Think of the possibilities, you can create these links in your email promos.
Visitors will not make a purchase and call to say "I forgot to apply my code from the email, can I still get my discount"
I you want to email a customer a special discount code, you can just say, "click this link to apply your code"
Make a social media post with a code without actually having to say what the code is.. Just click the link to activate the code.
At the bottom of the page, just before the closing </body> tag, add the following code

<!-- begin coupon code populate -->
<% if request.querystring("action")<>"" then %>
<script type="text/javascript">

function getQueryString() {
var qs = document.location.search,pairs,pair,key,value,el,i,n;
if (qs.length > 0) {
qs = qs.substr(1);
pairs = qs.split(/&/);
for (i = 0, n = pairs.length; i < n; i++) {
pair = pairs[i].split(/=/);
key = pair[0];
value = decodeURIComponent(pair[1].replace(/\+/g, " "));
el = document.getElementById(key);
if (el) {
el.value = value;
}
}
pairs = null;
pair = null;
el = null;
}
}

window.addEventListener('load',getQueryString,false);
window.addEventListener('load',applycert,false);
if(window.attachEvent){
window.attachEvent('onload',getQueryString);
window.attachEvent('onload',applycert);
}
</script>
<% end if %>
<!-- end coupon code populate -->


Step 4 (only if you opted into step 3 )
Create your URL that will populate your code on that page.

www.yoursite.com/websitename-discount-coupon-codes.asp?action=applycert&cpncode=YOURCOUPONCODE

The part in red there is the querystring and you want it entered exactly as it is here, with the exception of your desired code there at the end in place of YOURCOUPONCODE

David
ECT Power User

Edited by - dbdave on 09/09/2017 15:16:36

dbdave
ECT Moderator

USA
8024 Posts

Posted - 09/09/2017 :  20:25:53  
If you want to apply a code on the product detail page with the querystring and not show the coupon code entry box, use the following

Add this to the bottom of your proddetail.asp page just before the closing body (</body>) tag


<!-- begin coupon code populate -->
<% if request.querystring("action")<>"" then %>
<%
cpnarr=split(trim(SESSION("cpncode")), " ")
for index=0 to UBOUND(cpnarr)
next
print "<input id=""cpncode"" type=""hidden""/>"
%>
<script type="text/javascript">
function getQueryString() {
var qs = document.location.search,pairs,pair,key,value,el,i,n;
if (qs.length > 0) {
qs = qs.substr(1);
pairs = qs.split(/&/);
for (i = 0, n = pairs.length; i < n; i++) {
pair = pairs[i].split(/=/);
key = pair[0];
value = decodeURIComponent(pair[1].replace(/\+/g, " "));
el = document.getElementById(key);
if (el) {
el.value = value;
}
}
pairs = null;
pair = null;
el = null;
}
}

function applycertcallback(){
if(ajaxobj.readyState==4){
var retvals=ajaxobj.responseText.split('&');
alert(retvals[1]);
if(retvals[0]=='success'){document.getElementById("cpncode").value='';}
}
}
function applycert(){
var cpncode=document.getElementById("cpncode").value;
if(cpncode!=""){
ajaxobj=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("MSXML2.XMLHTTP");
ajaxobj.onreadystatechange=applycertcallback;
ajaxobj.open("GET", "vsadmin/ajaxservice.asp?action=applycert&stg1=1&cpncode="+cpncode, true);
ajaxobj.send(null);
}
}

window.addEventListener('load',getQueryString,false);
window.addEventListener('load',applycert,false);
if(window.attachEvent){
window.attachEvent('onload',getQueryString);
window.attachEvent('onload',applycert);
}
</script>
<% end if %>
<!-- end coupon code populate -->


Then send your link like this
www.yoursite.com/proddetail.asp?prod=someproduct&action=applycert&cpncode=YOURCOUPONCODE

The part in red there is what you want entered exactly as it is here, with the exception of your desired code there at the end in place of YOURCOUPONCODE
If you are using a static page or addresses, just add the querystring to your normal link to that product
www.yoursite.com/someproduct?action=applycert&cpncode=YOURCOUPONCODE
Just remember the querystring must start with a ? and additional parameters are added with the ampersand &

Once you have added this, and if you use the discount page I mentioned before, you can create links to the products and apply the discount code in one step.


David
ECT Power User

Edited by - dbdave on 09/09/2017 20:28:44
   Topic   
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Shopping Cart Software Forum for Ecommerce Templates © 2002-2019 ecommercetemplates.com
This page was generated in 0.02 seconds. Snitz Forums 2000