multiple flat shipping rates

mreeemreee Member
in Help edited October 2013
Right now I have 3 multiple flat rates a free domestic, 9.90 international and, and 4.90 for a domestic free offer.

I want to sell wholesale through foxycart so I need to add shipping if people are ordering over $1000. I also want to give them the option to use their own carrier so I want a contact us option as well. International orders will need to contact us to figure it out.

This is what I have so far, but none of the over $1000 work.
/* BEGIN CUSTOM SHIPPING LOGIC */
 
var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
removeCustomShippingContainer(); // This call will make sure that when it updates, it starts fresh.
var sub_tot = fc_json.total_price;
//for free \/\/
if (sub_tot >= 10 && country_code == "US") {
  addShippingOption(3, 0, '', 'Free Shipping');
}//for int/concato wholesale \/\/
 else if (sub_tot >= 1000) {
  postage = 0 + (0 * (fc_json.product_count - 1));
  addShippingOption(1, postage, 'Your Carrier', 'Contact Us');
}//for us wholesale \/\/
 else if (sub_tot >= 1000 && country_code == "US") {
  postage = 91 + (91 * (fc_json.product_count - 1));
  addShippingOption(1, postage, 'USPS', 'Air');

  postage = 0 + (0 * (fc_json.product_count - 1));
  addShippingOption(1, postage, 'Your Carrier', 'Contact Us');
}//for us and int over 10 \/\/
 else if (country_code == "US") {
  postage = 4.9 + (4.9 * (fc_json.product_count - 1));
  addShippingOption(1, postage, 'USPS', 'Standard');
} else {
  postage = 9.9 + (9.9 * (fc_json.product_count - 1));
  addShippingOption(2, postage, 'USPS', 'International');
}
jQuery("#fc_shipping_methods_inner input[type='radio']:first").trigger("click");

/* END CUSTOM SHIPPING LOGIC */


My store is:
1hourbreak.com/online-shop/
Comments
  • winstonwinston FoxyCart Team
    @mreee

    The issue with that is a Javascript if/else loop will break at the first true logic, so the way you have it working it will only see that someone is in the US and add the free shipping but never get to the other logic. I reworked it for you to cover the 4 options it looks like you have: US, over 10 & under 1000, International over 10 & under 1000, International over 1000 and US over 1000:
    /* BEGIN CUSTOM SHIPPING LOGIC */
     
    var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
    removeCustomShippingContainer(); // This call will make sure that when it updates, it starts fresh.
    var sub_tot = fc_json.total_price;
    if (sub_tot >= 10 && sub_tot < 1000 && country_code == "US") {
      addShippingOption(3, 0, '', 'Free Shipping');
      var postage_usps = 4.9 + (4.9 * (fc_json.product_count - 1));
      addShippingOption(1, postage_usps, 'USPS', 'Standard');
    } else if (sub_tot >= 10 && sub_tot < 1000 && country_code != "US") {
      var postage_int = 9.9 + (9.9 * (fc_json.product_count - 1));
      addShippingOption(2, postage_int, 'USPS', 'International');
    } else if (sub_tot >= 1000 && country_code != "US") {
      var postage_custom = 0 + (0 * (fc_json.product_count - 1));
      addShippingOption(1, postage_custom, 'Your Carrier', 'Contact Us');
    } else if (sub_tot >= 1000 && country_code == "US") {
      var postage_usps = 91 + (91 * (fc_json.product_count - 1));
      addShippingOption(1, postage_usps, 'USPS', 'Air');
      var postage_custom = 0;
      addShippingOption(1, postage_custom, 'Your Carrier', 'Contact Us');
    }
    jQuery("#fc_shipping_methods_inner input[type='radio']:first").trigger("click");
    

    Let me know if that works for you!
  • @winston

    Thanks for the help. The only problem is that if someone has less than $10 item in the cart they should have to pay 4.90 shipping. In your code it is the first part of the if statement. Where should I put it so that it doesn't break the logic?

    Thanks!
  • winstonwinston FoxyCart Team
    @mreee

    Do you want all purchases under $1000 in the US to be $4.90, and internationally to be $9.90? If so, that would just be like this:
    /* BEGIN CUSTOM SHIPPING LOGIC */
     
    var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
    removeCustomShippingContainer(); // This call will make sure that when it updates, it starts fresh.
    var sub_tot = fc_json.total_price;
    if (sub_tot < 1000 && country_code == "US") {
      addShippingOption(3, 0, '', 'Free Shipping');
      var postage_usps = 4.9 + (4.9 * (fc_json.product_count - 1));
      addShippingOption(1, postage_usps, 'USPS', 'Standard');
    } else if (sub_tot < 1000 && country_code != "US") {
      var postage_int = 9.9 + (9.9 * (fc_json.product_count - 1));
      addShippingOption(2, postage_int, 'USPS', 'International');
    } else if (sub_tot >= 1000 && country_code != "US") {
      var postage_custom = 0 + (0 * (fc_json.product_count - 1));
      addShippingOption(1, postage_custom, 'Your Carrier', 'Contact Us');
    } else if (sub_tot >= 1000 && country_code == "US") {
      var postage_usps = 91 + (91 * (fc_json.product_count - 1));
      addShippingOption(1, postage_usps, 'USPS', 'Air');
      var postage_custom = 0;
      addShippingOption(1, postage_custom, 'Your Carrier', 'Contact Us');
    }
    jQuery("#fc_shipping_methods_inner input[type='radio']:first").trigger("click");
    
  • It should be

    Less than $10 domestic is 4.90
    Less than $10 international is 9.90
    $10 - $1000 domestic is free
    $10 - $1000 international is 9.90
    over $1000 domestic is 91 or contact us
    over $1000 international is contact us

    Sorry for the confusion. The thing that is still not working is the first thing on the list, 4.90 for domestic.
  • winstonwinston FoxyCart Team
    @mreee

    Sorry that I missed that in your original logic. Pretty sure I straightened things out here:
    /* BEGIN CUSTOM SHIPPING LOGIC */
     
    var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
    removeCustomShippingContainer(); // This call will make sure that when it updates, it starts fresh.
    var sub_tot = fc_json.total_price;
    if (sub_tot < 10 && country_code == "US") { // less that $10 in US is 4.90
      var postage_usps = 4.9 + (4.9 * (fc_json.product_count - 1));
      addShippingOption(1, postage_usps, 'USPS', 'Standard');
    } else if (sub_tot >= 10 && sub_tot < 1000 && country_code == "US") { // between 10 & 1000 in US is free
      addShippingOption(3, 0, '', 'Free Shipping');
    } else if (sub_tot < 1000 && country_code != "US") { // less than 1000 international is 9.90
      var postage_int = 9.9 + (9.9 * (fc_json.product_count - 1));
      addShippingOption(2, postage_int, 'USPS', 'International');
    } else if (sub_tot >= 1000 && country_code != "US") {  // greater than 1000 int is contact us
      var postage_custom = 0 + (0 * (fc_json.product_count - 1));
      addShippingOption(1, postage_custom, 'Your Carrier', 'Contact Us');
    } else if (sub_tot >= 1000 && country_code == "US") { // greater than 1000 us is 91 or contact us
      var postage_usps = 91 + (91 * (fc_json.product_count - 1));
      addShippingOption(1, postage_usps, 'USPS', 'Air');
      var postage_custom = 0;
      addShippingOption(1, postage_custom, 'Your Carrier', 'Contact Us');
    }
    jQuery("#fc_shipping_methods_inner input[type='radio']:first").trigger("click");
    
Sign In or Register to comment.