type:
snippet
category:
shipping
name:
Flat Rate Markup of Live Rates
versions:
0.6.0, 0.7.0, 0.7.1, 0.7.2, 1.0, 1.1
reference:
http://forum.foxycart.com/discussion/5385/fedex-rates-incorrect
tags:
snippets, shipping, advance
date:
2012-01-11

Flat Rate Markup of Live Rates

Versions 0.7.1 and older: Note that applying javascript shipping modifications using either live or flat rates where you are setting custom values has been found to not work as expected for subscription based products where you need the shipping to apply to each subscription renewal. A fix is in place for versions 0.7.2 and newer.

Sometimes you may need to increase a certain live rate or group of live rates by a certain amount to add your own markup to the returned rates from the shipping provider. This script allows you to do just that, with this script being designed to run after the shipping rates are returned. Paste the code just before the closing </head> tag of your checkout template and edit as needed.

<script type="text/javascript">
jQuery(document).ajaxComplete(function(event, request, settings) {
  if (settings.url.indexOf('GetShippingCost') != -1) {
    jQuery("#fc_shipping_methods_inner input[name='shipping_service']").each(function() {
      var carrier = jQuery(this).siblings(".fc_shipping_carrier").html();
      var inputVal = jQuery(this).val().split("|");
      var id = parseInt(inputVal[0]);
      var price = parseFloat(inputVal[1]);
 
      // BEGIN CUSTOM LOGIC
      // Add your logic below, creating teirs based on the 'carrier' (the carrier of the rate - "FedEx", "UPS" etc), 'id' (each rate type has a unique ID in FoxyCart) and 'price' (the returned rate)
 
      if (carrier == "FedEx") {
        price += 4;
      }
 
      // END CUSTOM LOGIC
 
      if (!jQuery(this).data('price-edited')) {
        jQuery(this).val(id+"|"+price).data('price-edited',true).siblings("span.fc_shipping_cost").html(FC.formatter.currency(price, true));
      }
    });
  }
});
</script>

You can add anything you want within that code, and it will only be run when the shipping rate requests returns.

Site Tools