wojodesign/simplecart-js — pull request #475 by danmcb (2014-07-21 09:59:40+00:00)
Title: add option for customDiscount option

This hack allows the user to define a customDiscount function which
returns a discount as a number from 0-100 (i.e. a percentage). If the
function is not defined it defaults to 0. The discount is applied to the
total before shipping. (I would like also that the class
.simpleCart_discount could be used in html, but didn't succeed in doing
that.) I think that this is a simple and flexible way to implement
discounts, which seems to be a common requirement.

Something would really need to be added in the docs for this as well. Here is an example customDiscount function:

/* offer a 20% discount on quantities greater than 5 */
simpleCart.discount(function(){
var cq = simpleCart.quantity();
var discount = 0;
if ( cq > 5) {
discount = 20;
}
return discount;
});