Discount code

Anonymous_User
Not applicable

Hi,

I am trying to create a discount code for the buy now button contained within my website on this page; https://www.cptcycling.co.uk/verve-infocrank.php I have used and edited some of the script from this help page; https://www.paypal.com/uk/smarthelp/article/how-do-i-create-a-discount-code-or-coupon-code-for-my-pa... So far having successfully enabling a discount code and notifications, but not successful yet in the % discount to be applied within the cart.

The following is where I got to so far with Java script:

<script type="text/javascript">
<!--
var discnt = 0; // no default percent discount

var coupons = new Array ( // place to put coupon codes
"CPTcoached20", // 1st coupon value - comma seperated
"CPTcoached20", // 2nd coupon value - add all you want
"CPTcoached20" // 3rd coupon value
);
var coupdc = new Array ( // place to put discounts for coupon vals
20,
20,
20,
);
var coupval = "(blanket)"; // what user entered as coupon code

function ChkCoup () { // check user coupon entry
var i;
discnt = 0; // assume the worst
for (i=0; i<coupons.length; i++) {
if (coupval == coupons[i]) {
discnt = coupdc[i]; // remember the discount amt
alert ("That's valid coupon code. \n\n" + discnt +
"% discount how now been applied.");
return;
}
}
alert ("'" + coupval + "' is not a valid code");
}

function Pound (val) { // force to valid dollar amount
var str,pos,rnd=0;
if (val < .995) rnd = 1; // for old Netscape browsers
str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape
pos = str.indexOf (".");
if (pos > 0) str = str.substring (rnd, pos + 3);
return str;
}

function ReadForm (obj1) { // apply the discount
var amt,des;
amt = obj1.baseamt.value*1.0; // base amount
des = obj1.basedes.value; // base description

if (discnt > 0) { // only if discount is active
amt = Pound (amt - (amt * discnt/100.0));
des = des + ", " + discnt + "% dis, COUP =" + coupval;
}

obj1.amount.value = Pound (amt);
obj1.item_name.value = des;
}
//-->
</script>

 

Any help greatly appreciated.

Thanks,

Richard

Login to Me Too
1 REPLY 1

Giusé
Contributor
Contributor

I have the same issue with the same code, trying to make a coupon.

I can't solve the problem, I hope someone will help us.

 

I realised in the code there is a string saying "for old Netscape browsers"...

I hope couldn't be a browser issue... or maybe it's just an old script that needs updates...

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.