| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| snippets:shipping:free_shipping_using_a_coupon [2012/04/30 12:59] – [Setup 1: Free shipping using a 0% discount coupon] adam | snippets:shipping:free_shipping_using_a_coupon [2022/04/07 19:12] (current) – [Related Forum Discussions] marija |
|---|
| ---- dataentry snippet ---- | ---- dataentry snippet ---- |
| type : snippet #do not change this line | type : snippet # do not change this line |
| category : shipping #mention the category like 'shipping', 'checkout' etc | category : shipping # mention the category like 'shipping', 'checkout' etc |
| name : Free shipping using a coupon #the name of the snippet | name : Free shipping using a coupon # the name of the snippet |
| description : #description about snippet | description : # description about snippet |
| versions_tags : 0.6.0, 0.7.0, 0.7.1, 0.7.2 #compatible versions | versions_tags : 0.6.0, 0.7.0, 0.7.1, 0.7.2, 1.0, 1.1 # compatible versions |
| reference_url : http://forum.foxycart.com/comments.php?DiscussionID=4487&page=1 #Item_1 # External link | reference_url : https://forum.foxycart.com/discussion/4487 # Item_1 # External link |
| tags_tags : snippets, shipping, advance #tags, separated by commas. | tags_tags : snippets, shipping, advance # tags, separated by commas. |
| date_dt : 2011-05-27 #the date in YYYY-MM-DD format | date_dt : 2011-05-27 # the date in YYYY-MM-DD format |
| ---- | ---- |
| | |
| | |
| ===== Setup 1: Free shipping using a 0% discount coupon ===== | ===== Setup 1: Free shipping using a 0% discount coupon ===== |
| |
| | <WRAP center round important 80%> |
| | **Using version 2.0?** There is a new snippet available for our latest version, [[v:2.0:snippets|available from here]]. |
| | </WRAP> |
| ==== Step 1: Add a coupon ==== | ==== Step 1: Add a coupon ==== |
| |
| First, set up a coupon for a 0% discount for one or more items. Give it a code (for the example, we'll use "SHIP4FREE") and a name ("Free Shipping!"). Note that this code relies on the coupon name having the string "free shipping" within the name. Case doesn't matter, so you can have it in all capitals, sentence case or however you like - as long as it appears within it's name somewhere. So for example "Free Shipping!", "100% Free Shipping for all!" and "fReE sHiPpInG" are all valid for this code (although that last one isn't advised :). "Free quick shipping" however is not. | First, set up a coupon - and depending on your store version, you will need to setup different coupons. |
| |
| ==== Step 2: Enable free shipping live rate ==== | * **For FoxyCart 0.7.1 and older:** Create a coupon of the type "Amount based on the quantity" with a discount string of ''1-0.01'' |
| | * **For FoxyCart 0.7.2 and newer:** Create a coupon of the type "Percentage based on the quantity" with a discount string of ''1-0''. Note that a discount of 0 will mean that the coupon use won't be noted against order emails or the transaction report in the administration. If that is an issue, you'll want to use the previous $0.01 discount. |
| |
| Then, enable free shipping on your account (in the Foxycart admin: STORE -> shipping -> CUSTOM OPTIONS -> custom domestic services -> free ground shipping). If you like, you can also rename the option to "In-Store Pickup" or something like that, so that if the script fails to hide the option it won't result in customers expecting free shipping. | Give it a code and a name like ("Free Shipping!"). Note that this script relies on the coupon name having the string "free shipping" within the name. Case doesn't matter, so you can have it in all capitals, sentence case or however you like - as long as it appears within it's name somewhere. So for example "__Free Shipping__!", "100% __Free Shipping__ for all!" and "__fReE sHiPpInG__" are all valid for this code (although that last one isn't advised :). "__Free__ quick __shipping__" however is not. |
| | |
| | ==== Step 2: Enable free shipping live rate ==== |
| |
| | Then, enable free shipping on your account (in the Foxycart admin: STORE -> shipping -> CUSTOM OPTIONS -> custom domestic services -> free ground shipping). You can also rename that option to be whatever you want in the languages section of the administration. |
| |
| ==== Step 3: Add javascript ==== | ==== Step 3: Add javascript ==== |
| |
| Then, in your checkout script, include the following javascript: | Then, in your checkout script, include the following javascript - pasting it right before the closing ''</head>'' tag of your checkout template: |
| |
| <code javascript> | <code javascript> |
| <script type="text/javascript"> | <script type="text/javascript"> |
| jQuery(document).ready(function(){ | jQuery(document).ready(function(){ |
| jQuery("#fc_shipping_methods_inner").ajaxComplete(function(event, request, settings) { | jQuery(document).ajaxComplete(function(event, request, settings) { |
| jQuery("label[for='shipping_service_60']").hide(); | jQuery("label[for='shipping_service_60']").hide(); |
| if(fc_json.hasOwnProperty('coupons')) { | if(fc_json.hasOwnProperty('coupons')) { |
| </code> | </code> |
| |
| ===== Related Forum Discussions ===== | |
| |
| * http://forum.foxycart.com/comments.php?DiscussionID=4487&page=1#Item_1 | |
| |
| |
| jQuery(document).ready(function() { | jQuery(document).ready(function() { |
| if (fc_json.custom_fields[FCcode] == "true") { | if (fc_json.custom_fields[FCcode] == "true") { |
| jQuery("#fc_cart_foot_discount_new").before('<tr class="fc_cart_foot_discount"><td colspan="2" class="fc_col1">Free Shipping:</td><td class="fc_col2"><span class="fc_discount">TBD</span><span class="fc_cart_coupon_remove"><a title="Remove this coupon" class="fc_cart_remove_link" href="https://'+window.location.hostname+'/cart.php?h:'+FCcode+'=false">[x]</a></span></td></tr>'); | var colspan = jQuery("#fc_cart_table tr.fc_cart_item:first td").length - 1; |
| | jQuery("#fc_cart_foot_discount_new").before('<tr class="fc_cart_foot_discount"><td colspan="' + colspan + '" class="fc_col1">Free Shipping:</td><td class="fc_col2"><span class="fc_discount">TBD</span><span class="fc_cart_coupon_remove"><a title="Remove this coupon" class="fc_cart_remove_link" href="https://'+window.location.hostname+'/cart.php?h:'+FCcode+'=false">[x]</a></span></td></tr>'); |
| } | } |
| }); | }); |
| | |
| if (fc_json.custom_fields[FCcode] == "true") { | if (fc_json.custom_fields[FCcode] == "true") { |
| jQuery("#fc_cart_foot_shipping").before('<tr id="freeshipping" class="fc_cart_foot_discount"><td colspan="2" class="fc_col1">Free Shipping:</td><td class="fc_col2"><span class="fc_discount"> </span></td></tr>'); | var colspan = jQuery("#fc_cart_table tr.fc_cart_item:first td").length - 1; |
| | jQuery("#fc_cart_foot_shipping").before('<tr id="freeshipping" class="fc_cart_foot_discount"><td colspan="' + colspan + '" class="fc_col1">Free Shipping:</td><td class="fc_col2"><span class="fc_discount">APPLIED</span></td></tr>'); |
| } | } |
| | |
| jQuery("#fc_shipping_methods_inner").ajaxComplete(function(event, request, settings) { | jQuery(document).ajaxComplete(function(event, request, settings) { |
| if (settings.url.indexOf('GetShippingCost') != -1) { | if (settings.url.indexOf('GetShippingCost') != -1) { |
| checkFreeShip(); | checkFreeShip(); |
| jQuery(document).ready(function() { | jQuery(document).ready(function() { |
| if (fc_json.custom_fields[FCcode] == "true") { | if (fc_json.custom_fields[FCcode] == "true") { |
| jQuery("#fc_cart_foot_shipping").before('<tr id="freeshipping" class="fc_cart_foot_discount"><td colspan="2" class="fc_col1">Free Shipping:</td><td class="fc_col2"><span class="fc_discount"> </span></td></tr>'); | var colspan = jQuery("#fc_cart_table tr.fc_cart_item:first td").length - 1; |
| | jQuery("#fc_cart_foot_shipping").before('<tr id="freeshipping" class="fc_cart_foot_discount"><td colspan="' + colspan + '" class="fc_col1">Free Shipping:</td><td class="fc_col2"><span class="fc_discount">APPLIED</span></td></tr>'); |
| } | } |
| | |
| jQuery(document).ready(function() { | jQuery(document).ready(function() { |
| if (fc_json.custom_fields[FCcode] == "true") { | if (fc_json.custom_fields[FCcode] == "true") { |
| jQuery("#fc_cart_foot_shipping").before('<tr id="freeshipping" class="fc_cart_foot_discount"><td colspan="2" class="fc_col1">Free Shipping:</td><td class="fc_col2"><span class="fc_discount"> </span></td></tr>'); | var colspan = jQuery("#fc_cart_table tr.fc_cart_item:first td").length - 1; |
| | jQuery("#fc_cart_foot_shipping").before('<tr id="freeshipping" class="fc_cart_foot_discount"><td colspan="' + colspan + '" class="fc_col1">Free Shipping:</td><td class="fc_col2"><span class="fc_discount"> </span></td></tr>'); |
| } | } |
| }); | }); |