Maximum flat rate shipping cost if products from several categories

intandemintandem Member
in Help edited November 2012
I have 2 categories of products, each with 2 flat rate shipping costs, based on address. This is all set up and working.
However, if the customer buys one product from category A plus another from category B, checkout currently will add the two flat rate shipping fees together. However, I just want to charge them the higher rate once (e.g. product A has flat rate of 5.00, product B has flat rate of 10.00, both ordered in one shipment - I don't want shipping total of 15.00 but rather 10.00). Can this be done?
Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @intandem,

    It's possible, but at this time it requires some javascript on your checkout. So instead of setting those flat rates on your admin, you'd actually set those to 0 and instead set it on your checkout. This snippet should get you started - http://wiki.foxycart.com/snippets/shipping/tiered_flat_rate_shipping, but if you need a hand if you could let me know your categories I can quickly write up that custom logic for you. In essence though it would look like this:
    var catA = false;
    var catB = false;
    for (var p in fc_json.products) {
      switch (fc_json.products[p].category) {
        case "catA":
          catA = true;
          break;
        case "catB":
          catB = true;
          break;
      }
    }
      
    if (catA) {
      shippingCost = 5;
    }
    if (catB) {
      shippingCost = 10;
    }
    

    If you just have to two categories, just update each place catA and catB are mentioned to instead be the category code of your relevant categories
  • Hey Adam

    This is for my shopping cart that we dealt with before, i.e. the Dublin/Ireland cart, so it might be more complex? I thought there might be something in the system settings that I simply need to set up. But if it has to go back into the Javascript, then it's probably more complex as I have the flat rates by category AND delivery area. Will I get in touch with one of the guys? Thanks!
  • fc_adamfc_adam FoxyCart Team
    @intandem,

    Unfortunately at this time the shipping setup is a little restrictive, so you can't do something like say 'use the most expensive flat rate shipping cost' without getting into some javascript.

    Looking back over our previous thread (sorry I didn't remember that!), but based on what I believe is the last working code for the shipping logic, this should do what you want: http://pastie.org/private/vh8vb1phrmkozmn1ysprbg

    Just switch that out for the code that matches up in your current template.
  • Unfortunately, that doesn't seem to work. Gives me no shipping costs at all, no matter what address etc. I'm using.

    This is my current code: http://pastie.org/5171420 (works perfectly for address/category flat shipping we set up before)

    And this is how I switched it out with your new code: http://pastie.org/5171421

    Thanks!
  • fc_adamfc_adam FoxyCart Team
    @intandem,

    It does look to be working for me - with one exception, change this line:
    if (country_code == "IE" && jQuery.inArray(state_name, validCounties) > -1) {
    

    To this:
    if (country_code == "IE" && state_code == "D") {
    

  • Brilliant, that's working now! Thanks!

    Is there something I can do to only show shipping charge once the address has been entered? At the moment, it shows 20.00 as soon as I open the cart, even before an address has been selected. That could put off customers who don't realise that with a certain address they can get a reduced shipping fee?
  • fc_adamfc_adam FoxyCart Team
    @intandem,

    You can - simply change this:
    onLoad: true
    

    To this:
    onLoad: false
    

    just above your custom shipping logic
  • That's great, thanks! Are you in a different time zone today? I'm not used to getting replies from you at this hour of the day ....
  • fc_adamfc_adam FoxyCart Team
    @intandem,

    I don't believe in time zones :)
Sign In or Register to comment.