This is an old revision of the document!


type:
snippet
category:
Add to cart form
name:
Automatically adding a coupon code
reference:
http://forum.foxycart.com/comments.php?DiscussionID=1993&page=1
tags:
snippets, shipping, advance
date:
2011-05-25

Automatically adding a coupon code

The code below is for automatically adding a coupon code in the background, on pageload.

v0.7.2+

fcc.events.cart.ready.add(function(){
    // check for coupon
    $.getJSON('http://example.foxycart.com/cart?output=json' + fcc.session_get() +'&cart=view&callback=?', function(data){
        if (!data.coupons) {
            $.getJSON('http://example.foxycart.com/cart?cart=update' + fcc.session_get() +'&coupon=free-special-product-shipping&callback=?', function(){
                // console.log('Coupon added.');
            });
        }
    });
    return true;
});

v0.6.0

function fc_BuildFoxyCart() {
// check for coupon
$.getJSON('http://example.foxycart.com/cart?output=json&cart=view&callback=?' + fc_AddSession(),
function(data){
if (!data.coupons) {
$.getJSON('http://example.foxycart.com/cart?cart=update&coupon=free-special-product-shipping&callback=?' + fc_AddSession(), function(){});
}
 
});
 
return true;
}

For further details, please see the forum link below.

Site Tools