type:
snippet
category:
shipping
name:
Conditional free shipping with live rates
versions:
0.6.0, 0.7.0, 0.7.1, 0.7.2, 1.0
reference:
http://forum.foxycart.com/comments.php?DiscussionID=1531
tags:
snippets, advance
date:
2011-05-25

Conditional free shipping with live rates

Using version 2.0? There is a new snippet available for our latest version, available from here.

When using live rates, you may want to include a free shipping option for customers who reach a certain threshold - like a certain number of products, or from a certain country.

Step 1: Enable free shipping option

Under 'Shipping' in the administration, check 'Use custom' and 'Free ground shipping' under 'Custom Options', and update the settings. You can also rename it to be whatever you want from within the 'Languages' section of the administration.

Step 2: Add Javascript

Paste the following code right before the closing </head> tag of your checkout template, updating the logic to match what you're checking against:

<script type="text/javascript" charset="utf-8" >
var myCustomShipping = function() {
  if (fc_json.total_price < 150) {
    // if the requirements *are not* met, then remove the free shipping option.
    jQuery("label[for='shipping_service_60']").remove();
  }
}
 
jQuery(document).ready(function() {
  jQuery(document).ajaxComplete(function(event, request, settings) {
    myCustomShipping();
  });
});
</script>

Site Tools