Skip to content

Instantly share code, notes, and snippets.

@wnstn
Created October 2, 2013 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wnstn/6801874 to your computer and use it in GitHub Desktop.
Save wnstn/6801874 to your computer and use it in GitHub Desktop.
FoxyCart flat rate shipping based on product count
<script type="text/javascript" charset="utf-8">
FC.checkout.config.customShipping = {
onLoad: true, // Set to false if you don't want shipping calculated when the checkout loads
onLocationChange: true // Set to true if your shipping logic relies on updating whenever the shipping location for the order changes
};
function calculateShipping() {
var shippingCost = 0;
/* BEGIN CUSTOM SHIPPING LOGIC */
var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
var amount = fc_json.product_count;
switch (country_code) {
case "GB":
shippingCost = 2.50;
break;
default:
shippingCost = 4.00;
}
/* END CUSTOM SHIPPING LOGIC */
FC.checkout.config.orderFlatRateShipping = shippingCost * amount;
FC.checkout.updateShipping(-1);
}
jQuery(document).ready(function() {
if (FC.checkout.config.customShipping.onLoad) {
runShippingLogic();
}
if (FC.checkout.config.customShipping.onLocationChange) {
FC.checkout.overload("updateTaxes", function() { runShippingLogic(); }, null);
}
});
function runShippingLogic() {
// Check to see if there are actually shippable products in the current cart before running the custom shipping (0.7.1+ only), or just run it for older carts
if ((typeof(FC.checkout.config.hasShippableProducts) === "boolean" && FC.checkout.config.hasShippableProducts) || typeof(FC.checkout.config.hasShippableProducts) === "undefined") {
calculateShipping();
}
}
</script>
@Neotheorist
Copy link

Hello,

I'm attempting to use foxycart with wix. I know exactly zero about code but found your post here. Is there a way to write code that will ad a set fee based on the cart dollar total? in tiers, i.e,. $0 to $80..00 = $8.00, $81.01 to $215.00 = $10.00, $215.01 to $350.00 = $15.00, $350.01 to $500.00 = $27.00.
Thank you for your response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment