type:
snippet
category:
shipping
name:
Handling fee on orders under $100, free if over, live rates included.
versions:
0.6.0, 0.7.0, 0.7.1, 0.7.2, 1.0
reference:
http://forum.foxycart.com/comments.php?DiscussionID=2898&page=1
tags:
snippets, shipping, advance
date:
2011-05-27

Handling fee on orders under $100, free if over, live rates included.

This javascript allows you to add different amounts to shipping costs based on the carrier that the customer has chosen. This particular setup also provides free shipping if the order is over a certain price.

Step 1: Javascript

Paste the following right before the closing </head> tag in your checkout template. You'll need to edit the script to show the values you want to add for each carrier.

<script type="text/javascript">
function updateMyShippingCost() {
  // Grab current shipping cost (from live rates)
  var shippingCost = FC.checkout.config.orderShipping;
 
  // Grab currently selected shipping option
  var carrier = $("input[name=shipping_service]:checked").siblings(".fc_shipping_carrier").html();
  if ( carrier != null ) { // something is selected
    if ( carrier == "FedEx" ) { // it's FedEx!
      shippingCost += 10;
    } else if ( carrier == "UPS" ) { // it's UPS!
      shippingCost += 3.5;
      if (fc_json.total_price >= 100) { // Free shipping!
        shippingCost = 0;
      }
    }
  }
  // Update the shipping cost with the updated figures
  FC.checkout.config.orderShipping = shippingCost;
}
 
jQuery(document).ready(function(){
  // set the custom function to run before the updatePriceDisplay function
  FC.checkout.overload("updatePriceDisplay", "updateMyShippingCost", null);
});
</script>

Site Tools