Calculate a discount for 3 or more of an item?

hop2us
Contributor
Contributor

I want to offer my clients a discount if they buy 3 or more of a single product.

 

I saw there is a variable for discount_amount and discount_amount2, but not sure this will work as it only seems to give the option from the 2nd item on. Can I make this so it works for the 3rd item and on?

 

Also, can I give them the option to add the quantity directly on the same page as the product along with the button?

Login to Me Too
3 REPLIES 3

snowshoe
Frequent Advisor
Frequent Advisor

What you have in mind is possible however, it requires some custom coding and some scripting.

 

Here one example:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>Button Example Code</title>

<!-- START META TAG SECTION -->
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="Content-Language" content="en">
<!-- END META TAG SECTION -->


<!-- Start of Script -->
<SCRIPT type=text/javascript>
<!--
var ac = 0;    // table for qty/amt pairs
var aqty = new Array ();  // qty brkpt
var aamt = new Array ();  // amount to charge

var pc = 0;    // table for qty/percent pairs
var pqty = new Array ();  // qty brkpt
var pper = new Array ();  // percent to discount

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) { // quantity based discounts
var i,amt,des,qty;
  amt = obj1.baseamt.value*1.0; // base amount
  des = obj1.basedes.value;     // base description
  qty = obj1.qty.value;         // get user quantity
  if (isNaN (qty) || qty < 1) { // make sure it's good
    alert ('"' + qty + '"' + ' is not a valid number!');
    ac = 0;                     // always zap the table
    pc = 0;
    return false;               // th-th-that's all, folks.
  }
  qty = qty*1.0;                // force to numeric

  for (i=ac-1; i>=0; i=i-1) {   // run table backwards
    if (qty >= aqty[i]) {       // use this entry
      amt = aamt[i];            // this is the real amount
      break;                    // get out, we're done
    }
  }
  for (i=pc-1; i>=0; i=i-1) {   // run table backwards
    if (qty >= pqty[i]) {       // use this entry
      amt = amt - (amt/100.0 * pper[i]);
      break;                    // get out, we're done
    }
  }

  obj1.item_name.value = des + ", " + qty + " Widget(s) @" +
                         Dollar (amt) + " each.";
  obj1.amount.value = Dollar (amt * qty);
  ac = 0;  // reset item discount
  pc = 0;
}

function SetAmt (q1, a1) {  // set up a quantity-based amount table
var i;
  ac = 0;
  for (i=0; i<arguments.length; i=i+2) {  // build the table
    aqty[ac] = arguments[i];   // get real args and store 
    aamt[ac] = arguments[i+1];
    ac = ac + 1;               // number of pairs in table
  }
}
//-->
</SCRIPT>
<!-- End of Script -->


</head>

<body>

<!-- START SAMPLE CODE SECTION -->


<!-- PARAGRAPH 1 -->
Discount &amp; Coupon Examples

<br><br>

Buy More, Pay Less - Add to Cart Item Button.

<br><br>

Widgets 
<br><br>
1-4 Widgets - $5.00 each
<br>
5-9 Widgets - $4.20 each
<br>
10 or More&nbsp;  - $3.30 each
<br><br>

<!-- Start of Add to Cart Form -->
<!-- Note: target="_self" was replaced with the variable target="_self" -->
<!-- Note: shopping_url also added to code -->
<!-- These two changes allow better functionality with IE and Firefox --> 
<FORM onsubmit="this.target = '_self'; SetAmt (1, 5.00, 5, 4.20, 10, 3.30); return ReadForm (this);" 
action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- If using a Business or Company Logo Graphic, include the "cpp_header_image" variable. -->
<input type="hidden" name="cpp_header_image" value="https://yourwebsite.com/logo.jpg"> 
<input type="hidden" value="_cart" name="cmd">
<input type="hidden" value="1" name="add"> 
<!-- Replace "business" value with your PayPal Email Address or Account ID -->
<input type="hidden" name="business" value="your email address">
<input type="hidden" name="item_name">
<input type="hidden" value="01-001" name="item_number"> 
<input type="hidden" name="amount">
<input type="hidden" value="2" name="no_shipping">
<!-- Replace value with the web page you want the customer to return to -->
<input type="hidden" name="shopping_url" value="http://www.yourwebsite.com/Shop.html">
<!-- Replace value with the web page you want the customer to return to after a successful transaction -->
<input type="hidden" name="return" value="http://www.yourwebsite.com/ThankYou.html">
<!-- Replace value with the web page you want the customer to return to after item cancellation -->
<input type="hidden" name="cancel_return" value="http://www.yourwebsite.com/Cancel.html">
<input type="hidden" value="USD" name="currency_code">
<input type="hidden" value="US" name="lc">
<input type="hidden" value=5.00 name="baseamt">
<input type="hidden" value="Widget" name="basedes"> 
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
Enter Desired Quantity:&nbsp;&nbsp;
<input size="3" value="1" name="qty">
<br><br>
<input type="reset" name="reset" value="Clear Selections" />
<br><br>
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</FORM>
<!-- End of Form -->

<br>

<!--  Start of View Cart Button Code  -->
<form target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- If using a Business or Company Logo Graphic, include the "cpp_header_image" variable. -->
<input type="hidden" name="cpp_header_image" value="https://yourwebsite.com/logo.jpg"> 
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="display" value="1">
<!-- Replace "business" value with your PayPal Email Address or Account ID -->
<input type="hidden" name="business" value="your email address">
<!-- Replace value with the web page you want the customer to return to -->
<input type="hidden" name="shopping_url" value="http://www.yourwebsite.com/Shop.html">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_viewcart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form> 
<!--  End of View Cart Button Code  -->



<!-- END BUTTON EXAMPLES -->



<!-- END SAMPLE CODE SECTION -->

<br><br>


<br><br><br><br>
<hr align="left" width="50%" noshade>
<br><br>
NOTES:
<br>
In order to test the code, you must replace the &quot;business&quot; value variable with your PayPal Email Address or Account ID.


</body>
</html>

 

Here's another approach that uses the "discount" variables:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>Button Example Code</title>

<!-- START META TAG SECTION -->
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="Content-Language" content="en">
<!-- END META TAG SECTION -->



</head>

<body>

<!-- START SAMPLE CODE SECTION -->


<!-- PARAGRAPH 1 -->
Discount &amp; Coupon Examples

<br><br>

Add to Cart - Save $.50 on each item.

<br><br>

Notes:<br>
Demonstrates the use of Discount Variables, &quot;discount_amount&quot; and &quot;discount_amount2&quot;.

<br><br>


<!-- START CONTENTS -->

<!-- START BUTTON EXAMPLES -->


Widget Candle - Online Special
<br>
Save $.50 on each Candle you Purchase!

<br><br>

<!-- Start of Add to Cart Form -->
<!-- Note: target="_self" was replaced with the variable target="_self" -->
<!-- Note: shopping_url also added to code -->
<!-- These two changes allow better functionality with IE and Firefox --> 
<form target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- If using a Business or Company Logo Graphic, include the "cpp_header_image" variable. -->
<input type="hidden" name="cpp_header_image" value="https://yourwebsite.com/logo.jpg"> 

<!-- Replace "business" value with your PayPal Email Address or Account ID -->
<input type="hidden" name="business" value="your email address">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="item_name" value="Widget Candle">
<input type="hidden" name="discount_amount" value=".50">
<input type="hidden" name="discount_amount2" value=".50">


<!-- Replace value with the web page you want the customer to return to -->
<input type="hidden" name="shopping_url" value="http://www.yourwebsite.com/Shop.html">
<!-- Replace value with the web page you want the customer to return to after a successful transaction -->
<input type="hidden" name="return" value="http://www.yourwebsite.com/ThankYou.html">
<!-- Replace value with the web page you want the customer to return to after item cancellation -->
<input type="hidden" name="cancel_return" value="http://www.yourwebsite.com/Cancel.html">

<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">


<!-- -->
Select Size:&#160;&#160;
<input type="hidden" name="on0" value="Size">
<select name="os0">
<option value="Small" selected>Small - $3.00</option>
<option value="Medium">Medium - $4.50</option>
<option value="Large">Large - $6.00</option>
</select>


<!-- option_index value=0 is associated with variable on0 -->
<input type="hidden" name="option_index" value="0">
<!-- -->
<input type="hidden" name="option_select0" value="Small">
<input type="hidden" name="option_amount0" value="3.00">
<input type="hidden" name="option_item_number0" value="WC-S-1001">
<!-- -->
<input type="hidden" name="option_select1" value="Medium">
<input type="hidden" name="option_amount1" value="4.50">
<input type="hidden" name="option_item_number1" value="WC-M-2002">
<!-- -->
<input type="hidden" name="option_select2" value="Large">
<input type="hidden" name="option_amount2" value="6.00">
<input type="hidden" name="option_item_number2" value="WC-L-3003">
<!-- -->


<br><br>
Select Scent:&#160;&#160;
<input type="hidden" name="on1" value="Scent">
<select name="os1">
<OPTION value="Blueberry" selected>Blueberry</OPTION>
<OPTION value="Vanilla">Vanilla</OPTION>
<OPTION value="Lemon">Lemon</OPTION>
<OPTION value="Apple Pie">Apple Pie</OPTION>
<OPTION value="Citrus">Citrus</OPTION>
<OPTION value="Rain">Rain</OPTION>
<OPTION value="Lavendar">Lavendar</OPTION>
<OPTION value="Jasmine">Jasmine</OPTION>
</select>

<br><br>
Quantity:&nbsp;&nbsp;
<input type="text" name="quantity" size="2">

<br><br>
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<!-- End of Form -->

<br>

<!--  Start of View Cart Button Code  -->
<form target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- If using a Business or Company Logo Graphic, include the "cpp_header_image" variable. -->
<input type="hidden" name="cpp_header_image" value="https://yourwebsite.com/logo.jpg"> 
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="display" value="1">
<!-- Replace "business" value with your PayPal Email Address or Account ID -->
<input type="hidden" name="business" value="your email address">
<!-- Replace value with the web page you want the customer to return to -->
<input type="hidden" name="shopping_url" value="http://www.yourwebsite.com/Shop.html">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_viewcart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form> 
<!--  End of View Cart Button Code  -->



<!-- END BUTTON EXAMPLES -->



<!-- END SAMPLE CODE SECTION -->

<br><br>


<br><br><br><br>
<hr align="left" width="50%" noshade>
<br><br>
NOTES:
<br>
In order to test the code, you must replace the &quot;business&quot; value variable with your PayPal Email Address or Account ID.


</body>
</html>

 

Login to Me Too

hop2us
Contributor
Contributor

That was so helpful.

 

The discount variable only seems to work so that you can change the price discount for the 2nd and more items, so it doesn't quite work for me.

 

The first example is great though. I only wonder, my site is done in Wordpress and is there a way to integrate the coding there since much of it is in the header area?

Login to Me Too

snowshoe
Frequent Advisor
Frequent Advisor

As with any programming, there's various ways to do the same thing.

 

Working with WordPress is a totally different animal.  Not sure how you can incorporate coding of this nature into WordPress.  It's much easier with other sites and/or hosts.

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.