---- dataentry snippet ---- type : snippet # do not change this line category : Add to cart form # mention the category like 'shipping', 'checkout' etc name : Automatically adding a coupon code # the name of the snippet description : # description about snippet versions_tags : 0.6.0, 0.7.2, 1.0, 1.1 # compatible versions reference_url : https://forum.foxycart.com/discussion/1993 # Item_12 # External link tags_tags : snippets, shipping, advance # tags, separated by commas. date_dt : 2011-05-25 # the date in YYYY-MM-DD format ---- ====== 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('https://' + storedomain + '/cart?output=json' + fcc.session_get() +'&cart=view&callback=?', function(data){ if (!data.coupons) { $.getJSON('https://' + storedomain + '/cart?cart=update&output=json' + fcc.session_get() +'&coupon=free-special-product-shipping&callback=?', function(data){ // console.log('Coupon added.'); FC.json = data; }); } }); return true; }); ==== v0.6.0 ==== function fc_BuildFoxyCart() { // check for coupon $.getJSON('https://example.foxycart.com/cart?output=json&cart=view&callback=?' + fc_AddSession(), function(data){ if (!data.coupons) { $.getJSON('https://example.foxycart.com/cart?cart=update&output=json&coupon=free-special-product-shipping&callback=?' + fc_AddSession(), function(data){ fc_json = data; }); } }); return true; } For further details, please see the forum link below. ===== Related Forum Discussions ===== * https://forum.foxycart.com/discussion/1993