---- dataentry snippet ----
type : snippet # do not change this line
category : shipping # mention the category like 'shipping', 'checkout' etc
name : Tiered Flat Rate Shipping # the name of the snippet
description : # description about snippet
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=2880&page=1 # Item_10 # External link
tags_tags : snippets, shipping, advance # tags, separated by commas.
date_dt : 2011-05-27 # the date in YYYY-MM-DD format
----
====== Tiered Flat Rate Shipping ======
**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.
**Using version 2.0?** There is a new snippet available for our latest version, [[v:2.0:snippets:flat_rate_shipping_modification|available from here]].
**If you're using handling fees** note that you can't overwrite handling fees using javascript on the checkout to provide free shipping. While it will appear that the shipping is $0 on the checkout, the handling fees will be added back in server-side, and the customer will see a shipping fee that matches the handling fee cost you have set in the administration.
Tiered Flat Rate Shipping, provides flat rates that are calculated based off of any values you want, like cart cost, total weight, products in the cart etc. Note that this applies the shipping automatically - if you want to provide selectable options, check out http://wiki.foxycart.com/snippets/shipping/multiple_flat_rates
==== Step 1: Update categories ====
Update all categories to 'Shipped using a flat rate fee' with a value of 0 in the 'Product Delivery Option' section.
==== Step 2: Add the javascript ====
Paste this code right before the closing '''' tag of your checkout template:
==== Step 3: Customise ====
Now the fun part - create your tiers to calculate your shipping and add your custom code between the /* BEGIN CUSTOM SHIPPING LOGIC */ and /* END CUSTOM SHIPPING LOGIC */ lines in the first script block. These can be as simple or as advanced as you want - see http://wiki.foxycart.com/static/redirect/jsonp for information on values in the JSON object.
With whatever custom logic you create, make sure you set the ''shippingCost'' variable with the desired shipping cost. This is what gets passed back to the checkout.
=== Examples ===
== Example 1: Product Count ==
This is a basic approach, and is easily interchangeable to total price, weight or other values.
var amount = fc_json.product_count;
if (amount <= 5) {
shippingCost += 5 * amount; // $5 per product
} else if (amount <= 10) {
shippingCost += 3 * amount; // $3 per product
} else if (amount <= 20) {
shippingCost += 2 * amount; // $2 per product
} else { // Must be 21 or more products
shippingCost = 0; // Free shipping because they bought so much
}
== Example 2: Shipping Country ==
For this approach, you'll need to set ''onLocationChange'' to true in Step 2.
var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
switch (country_code) {
case "US":
shippingCost = 10;
break;
case "CA":
shippingCost = 12;
break;
default:
shippingCost = 20;
}
===== Related Forum Discussions =====
* http://forum.foxycart.com/comments.php?DiscussionID=2880&page=1#Item_10