FoxyCart Custom Shipping Rates

I’ve just finished a small online FoxyCart/MODx store for a Scandinavian kids clothes range, and a requirement was different shipping rates for different countries, which a fairly common ask. There’s lots of different solutions out there for this, but I thought mine may be of some use as well. It works by:

  • Building your HTML fields based on a string
  • Updating the shipping amount on changing the country field
  • Detecting whether an alternative shipping address has been selected and favour this country field other the billing country field.

Something quite interesting I came across while building this little script was IE9 not processing the jQuery change() function. I am not sure whether this is specific to the version of jQuery which FoxyCart uses, but I did find a fix, which was using focusout() instead. It’s a fairly basic script, open to a lot of different scenarios, please feel free to modify at will!

View the script

Config

var currency : your store currency

Scroll down to the checkCountry() function. This handles the different shipping values for you and where you can create as many different conditions for as many different countries as you like. It uses the switch function to enable multiple types, but be sure to retain a default value. Example of shipping rates for the UK:

case ‘United Kingdom’:
createCountryShippingData(“UK Shipping=60|UK Shipping with tracking and insurance=300″);
break;

You’ll see that you can create a condition for a country and insert different values into the string using ShippingName=ShippingPrice separated by |. This should hopefully make the script recyclable.

The script is set up to charge per shipment, rather then per product, however I’ve written a little loop in which should be the starting place for you to be able to handle this

var delivery_1 = 60;
var delivery_2 = 300;

for (i = 0; i < fc_json.products.length; i++) {
var delivery_1 = delivery_1 + 60;
var delivery_2 = delivery_2 + 300;
}

You can then replace your values in the createCountryShippingData() function e.g.

createCountryShippingData(“UK Shipping=”+delivery_1+”|UK Shipping with tracking and insurance=”+delivery_2);

For more info on custom shipping ideas check out the foxycart documentation. There’s lots of room for other features to be built in, for instance different rates for different amounts of items or different shipping rates based on the order total. I have made a similar custom script which checks if the user is shipping to the UK and gives them free shipping over x amount. A full featured script to handle this would be pretty cool for the future, if it’s not being built in already.

BACK

One Response to FoxyCart Custom Shipping Rates

  1. Pingback: VingeBarna :: Norwegian Kids Clothing | Toasted Digital

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" extra="">