Help Article

Ask the Community

Find answers or join the conversation in the Community Help Forum.

How do I create a discount code or coupon code for my PayPal buttons?

PayPal doesn't support discount codes or coupons, but you can offer customers discounts by using a third-party shopping cart that supports a discount feature and works with PayPal.

You can also use a script to apply the discount to the amount and then pass that discounted amount to PayPal as the amount to charge. The sample script that follows applies a discount to all prices. Once you set it up, you can turn discounts on or off by changing one line of code. You can use this script on small sites where a single page displays all items for sale. If your site displays products across many pages, you must use cookies to "remember" the discount across those pages.

Here's how to create discount button code:
  1. Log in to your PayPal account.
  2. Click Tools.
  3. Click PayPal buttons.
  4. Click Select button for preferred button type.
  5. Enter your information to customize the button to your needs.
  6. Click Step 2: Track inventory, profit & loss and uncheck Save button at PayPal. (This ensures that you're creating a non-hosted button.)
  7. Click Create Button.
  8. Click Remove code protection. (You must do this to make your code editable.)
  9. Click Select Code to select the button code.
  10. Copy and paste the button code into your own webpage code.
This is the JavaScript code used to apply a 10 percent discount:
 
<script type="text/javascript">
<!--
discnt = 10; // set blanket 10% discount
//-->
</script>

The following button code uses the JavaScript shown above to apply a 10 percent discount. The first FORM command just gives the discount with no questions. Your site would proclaim a 10 percent discount on all products for the next week. The script displays the original prices on the site, but applies a 10 percent discount to all items ordered. To change the discount amount, edit the first line under the <script> tag. Setting the number to zero turns the discount off.
   
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = 'paypal';
discnt = 10;
coupval = '(blanket)';
ReadForm (this);
discnt = 0;">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="your_email_goes_here@your_site.com" />
<input type="hidden" name="item_name" value="Test Item" />
<input type="hidden" name="amount" value="10.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="lc" value="US" />
<input type="hidden" name="baseamt" value="10.00" />
Input quantity &gt;
<input type = "text"
name = "quantity"
value = "1"
size = "3" />
<input type="image" src="addcart.gif" name="submit" alt="cart add" />
</form>

You can also use JavaScript to generate broadcast coupons. A broadcast coupon is a coupon code available to all customers; if they enter it into your site, they get a discount.

The next example script prompts the user to enter a coupon code. If the user enters a valid code, the discount associated with that code is applied. You might want to place ads in several newspapers, each with a different coupon code to see which newspaper yields the best advertising results.

Note: For example purposes, the code entered is placed into the "item_number" field so you can see it. In reality, you might want to place the code in the "custom" field so no one but you can see it.

The following JavaScript is used for the broadcast coupon:
   
<script type="text/javascript">
<!--
var discnt = 0; // no default percent discount
var coupons = new Array ( // place to put coupon codes
"coup1", // 1st coupon value - comma seperated
"coup2", // 2nd coupon value - add all you want
"coup3" // 3rd coupon value
);
var coupdc = new Array ( // place to put discounts for coupon vals
5,
10,
15
);
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 ("Valid coupon number! \n\n" + discnt +
"% discount now in effect.");
return;
}
}
alert ("'" + coupval + "' is not a valid code!");
}
function Dollar (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 = Dollar (amt - (amt * discnt/100.0));
des = des + ", " + discnt + "% dis, COUP = " + coupval;
}
obj1.amount.value = Dollar (amt);
obj1.item_name.value = des;
}
//-->
</script>

The following button code would be used with the coupon code script:
  
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = 'paypal';
return ReadForm (this);">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="your_email_goes_here@your_site.com" />
<input type="hidden" name="item_name" value="2nd Item" />
<input type="hidden" name="amount" value="20.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="baseamt" value="20.00" />
<input type="hidden" name="basedes" value="2nd Item @20.00" />
Enter Coupon code [coup1] &gt;
<input type = "text"
size = "10"
name = "coupcode"; />
<input type="button" value="Check It"
onclick="coupval = this.form.coupcode.value;
ChkCoup();" />
Input quantity &gt;
<input type="text" name="quantity" value="1" size="4" />
<input type="image" src="addcart.gif" name="submit" alt="cart add" />
</form>
We’re sorry, the page you’re looking for is no longer available. Please try your search again in our Help Centre if you have a question or want to contact us.