Foxy Forum Status

We're no longer responding to questions via our forum, but we will keep it up for historical reasons. If you can't find the answer you're looking for, please visit our knowledge base or contact us. If there's enough interest in the future, we may bring the forum back.

Domestic Multi Option Flat Rate Shipping and International Flat Rate

BamSockPowBamSockPow Member
in Help edited March 2014
Hey Guys

I have a question that I've been having a little issue with, I want to update shipping costs so that there are two options for domestic (au) and one option for international, I have up until now been using this code which satisfies the previous brief perfectly until the addition of express shipping, not so much a json developer so any help would be awesome!

What is now
Domestic 5
International 15

What is wanted is
Domestic 5
Domestic Express 10
International 15

I've already had customers pay 5 dollar shipping when they are international so far which is quite frustrating as you could imagine.

FC.checkout.config.customShipping = {
  onLoad: false,  // 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;
var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
switch (country_code) {
  case "AU":
    shippingCost = 5;
    shippingCost = 15;
  • winstonwinston FoxyCart Team

    I think if you're adding multiple cases like that, you should try using our Multiple Flat Rate snippet: It's a bit more flexible and powerful.

    Your logic would need to be something like
    var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
    if (country_code === "AU" ){
    addShippingOption(1, 5, '', 'Domestic');
    addShippingOption(2, 10, '', 'Domestic Express');
    } else {
    addShippingOption(3, 15, '', 'International);

    Please test that out and let me know if it works as you want!
  • Thanks Winston!

    Heres the code I ended up using a mix and match of yours and the snippet code on the faq you linked me to
    if (typeof(country_code) === "undefined") {country_code = "";}
    new_country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
    if (country_code != new_country_code) { // The shipping country has changed!
      country_code = new_country_code;
      removeCustomShippingContainer(); // This call will make sure that when it updates, it starts fresh.
      if (country_code == "AU") {
    addShippingOption(1, 5, '', 'Domestic');
    addShippingOption(2, 10, '', 'Domestic Express');
      } else {
    addShippingOption(3, 15, '', 'International');

    Anyone whos looking for a quick code fix the above goes hand in hand with
    and allows you to set multiple domestic flatrate shipping options (regular and express) and a singular international flatrate

    The reason for changing from what you suggested
    It was compounding shipping options - It keeps adding them to the container so you swap between au and uk back to au and you end up with: domestic domestic express international domestic domestic express so the first half of the code after figuring out what was happening clears the field and then rewrites it with the options specified for that country

    Your logic for the shipping options is dead-on apart from an elusive ' that was missing on international (had my scratching my head for a little while)
Sign In or Register to comment.