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.

Free Shipping at Checkout if more than 1 product in the cart (with JS code)

ocorralocorral Member
in Help edited June 2012
Hi Team,
I have all 3 of my products in the DEFAULT category and I have flat-rate shipping setup for this category at $5.00. I would like it so that if the cart quantity is greater than 1 then the shipping automatically gets zero-ed out. After looking at the wiki and a lot of forum posts, I have put the following code in my checkout template above the head tag however it still doesn't seem to be working. Can you help me find out what's going wrong? Thanks :-)

You can view my almost ready site at http://dev.revolutiontrans63.com
function updateMyShippingCost() {
			var shippingCost = FC.checkout.config.orderShipping;
			for (i=0; i<fc_json.products.length;i++) {
					if (fc_json.products[i].category == "DEFAULT") {
						if (fc_json.product_count > 1) {
								shippingCost = 0;
						}
					}
			}
	
			FC.checkout.config.orderShipping = shippingCost;
	}
	
	jQuery(document).ready(function(){
		// set the custom function to run before the updatePriceDisplay function
		FC.checkout.overload("updatePriceDisplay", "updateMyShippingCost", null);
	});
Comments
  • fc_adamfc_adam FoxyCart Team
    @ocorral,

    You can actually do something much simpler than that for what you need:
    jQuery(document).ready(function() {
      var shippingCost = 5; // Default shipping cost
      if (fc_json.product_count > 1) {
        shippingCost = 0;
      }
      FC.checkout.config.orderFlatRateShipping = shippingCost;
      FC.checkout.updateShipping(-1);
    });
    

    Note that you'll also need to set your flat rate shipping setting in the administration to 0.
  • You rock. Works great. :-)
  • fc_adamfc_adam FoxyCart Team
    @ocorral,

    glad that worked for you!
  • Hi Adam,
    Just checking in with you after a couple months of having the live site.

    It turns out there have been a couple of customers who have managed to get by this javascript during checkout. I have no clue how that could be happening....

    We were getting people with 1 item getting free shipping so I decided to set the default flat rate shipping setting in the administration to 5 instead of 0 to prevent.

    Is there any reason the javascript would be failing or being ignored? I have not been able to replicate this behavior.
  • hummm just noticed jquery is being called twice in the checkout template.....not sure if that would cause it but I'm going to remove my jquery version just in case.
  • my checkout template now loads instantly. wow. what a difference. I guess that must have been hanging it.
  • fc_adamfc_adam FoxyCart Team
    @ocorral,

    Yeah - including a second (or more) versions of jQuery definitely isn't a good thing and will more often than not cause follow on issues.

    Just to note, make sure you set your flat rate setting back to 0 - as while the javascript will *appear* to make the shipping 0 on the checkout, if the setting in the admin is higher than that that's the figure that will get used.
  • Ah okay! Thank you. I switched it back. So far so good.
Sign In or Register to comment.