The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Free shipping in U.S. on one product

marketing_guymarketing_guy Member
in Help edited December 2012

I'm sure the code to use is this snippet, but I'm not sure what gets replaced with what. How do I make apply free shipping to just one product, and only if the shipping country for that one product is the U.S.?

Do I also need to set up a unique category just for the product or can the code account for that?

<script type="text/javascript" charset="utf-8" >
var myCustomShipping = function() {
  if (fc_json.total_price < 150) {
    // if the requirements *are not* met, then remove the free shipping option.
jQuery(document).ready(function() {
  jQuery("#fc_shipping_methods_inner").ajaxComplete(function(event, request, settings) {
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Look at the code here and see in particular the product loop. I think what you want to do is to say IF the country is X (see for some code on getting the country) THEN.....

    Set a variable for free_shipping = 1;
    Then do a loop through all your products and if there are any there that AREN'T called X or not in category Y then set free_shipping = 0;

    Then simply remove the free shipping service if the free_shipping == 0.

    That's the framework I'd use for doing this.
  • fc_adamfc_adam FoxyCart Team

    To clarify something - are you using live rates for your checkout? So when you say one product gets free shipping, that you want that product removed from the live rates calculations?
  • Hi,

    Yes, I'm using live rates on the store. For this one product, I want just customers in the United States to get free shipping on it. Everyone else would have live rate shipping. We're using USPS priority mail and international priority mail.
  • fc_adamfc_adam FoxyCart Team

    Sorry just to clarify - what happens if someone from the US buys that particular product, and another one with shipping? Would they just pay shipping for the other product?
  • Yes, the shipping rates would need to kick in for the other products. Right now, this product is the only one my client has with the free U.S. shipping offer.
  • fc_adamfc_adam FoxyCart Team

    So two things need to happen for your store.

    Firstly, before each rate request, you need to loop through the cart and check if the product that gets free shipping is present. If it is, and the customer is shipping to the US, you need to remove it's relevant weight from the orderShipmentWeight value in the checkout config object. This will prevent it from being included in live rate shipping requests.

    The other thing that might need to happen is to account for a situation where *only* the free shipping product is present and the customer is from the US. In this situation, the shipping endpoint would get a product weighing 0lb, which I'm not sure how it will respond, whether it will error, or give you some sort of base cost. Your best bet here would be to either reset the priority mail rate to $0 (if it doesn't error with 0lb shipment) or show the free ground shipping option that is available under custom shipping settings in your store's FoxyCart administration. With this option enabled, you'd also need to set that rate to be hidden if it's not needed, so someone can't score free shipping.

    How is your handle on javascript? You can get most of the way there with a snippet on our wiki for modifying the live rates to show/hide different rates. There is just a little extra javascript required to modify the weight before the rates are requested.

    If this is a little out of your depth, if you could let me know which store this is for that is under your account (I see two), I can give you a hand.
  • Hi,

    Appreciate the thorough explanation. Unfortunately my skills end at CSS and some very (very) basic PHP, so any guidance would be great.

    It's for the Natural Glow store, and the product is their marketing poster, seen here:
  • fc_adamfc_adam FoxyCart Team
    edited December 2012
    No worries - give this a try:

    Follow the instructions here:

    And when it comes time for the custom logic, use this:

    And paste this right before the snippet detailed in the steps on that wiki page:

    That should get you there. Note I haven't tested this, so make sure you test it thoroughly. Also, note that you'll need to put the poster into a category that is set to be shipped. Currently it's in the default category (because you haven't specified one in the add to cart) which is set to no shipping.

  • Excellent, thanks!

    It seems to be working. With the item in the cart, I set it to U.S. and it offered priority mail for zero, and Canadian postal codes set up international priority shipping. Do you know if live shipping on USPS international priority calculates based on weight?
  • Actually, spoke too soon. I just went into checkout with another item from a different category and it also set U.S. shipping to zero.
  • fc_adamfc_adam FoxyCart Team

    Oops, change this:
    if (fc_json.products[p].code = 1581) {

    To this:
    if (fc_json.products[p].code == 1581) {
Sign In or Register to comment.