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.

Future Subscription Shipping is charging at time of purchase

mreeemreee Member
in Help edited December 2013
I am setting up a free trial product with a 30 day subscription that starts 15 days later. I want the free trial to have a shipping cost but the subscription has free shipping.

The problem that I am running into is that since the user checks out with $0 cart value it is charging shipping for both the free trial and the future subscription. Is something wrong in with the way that I set up the checkout?

I am using the flat rate shipping, here is my code:
if (sub_tot < 10 && country_code == "US") { // less that $10 in US is 6.90
  var postage_usps = 6.9 + (6.9 * (fc_json.product_count - 1));
  addShippingOption(1, postage_usps, 'USPS', 'Standard');
  var postage_fast = 9.9 + (9.9 * (fc_json.product_count - 1)); //priority shipping domestic
  addShippingOption(1, postage_fast, 'USPS', 'Priority');
} else if (sub_tot >= 10 && sub_tot < 1000 && country_code == "US") { // over 10 US is free
  addShippingOption(3, 0, '', 'Free Shipping');
} else if (country_code != "US") { //international is 29.90
  var postage_int = 29.9 + (29.9 * (fc_json.product_count - 1));
  addShippingOption(2, postage_int, 'USPS', 'International');
}
Comments
  • fc_adamfc_adam FoxyCart Team
    @mreee,

    Ultimately the javascript based shipping snippets aren't standard shipping setups - these are essentally hacks of the shipping functionality to expand what it can do, but it won't be perfect in all instances.

    Could you link us to a page we can add this product to the cart and test? Feel free to whisper if it's private.
  • fc_adamfc_adam FoxyCart Team
    @mreee,

    I'm a little confused - it looks like it's all working fine from what I can see. The shipping rates are correctly calculating the shipping cost based on the subtotal.

    Could you perhaps clarify what you meant by:
    "The problem that I am running into is that since the user checks out with $0 cart value it is charging shipping for both the free trial and the future subscription."
  • fc_adamfc_adam FoxyCart Team
    Oh actually, are you saying that it's working out the cost for the shipping for 2 items, when it should just be one?

    If so, you could just change lines like this:
    var postage_usps = 6.9 + (6.9 * (fc_json.product_count - 1));
    

    To this:
    var postage_usps = 6.9;
    


    That first line that you currently have is saying that postage is 6.90 per product.
  • That makes sense. So when the subscription goes through 2 weeks later will the shipping be free since it is over $10.
  • fc_adamfc_adam FoxyCart Team
    @mreee,

    When the subscription renews, it doesn't rerun that logic in the checkout, but rather it just uses the settings as they were set at the time of checkout.

    You'll need to test that to see how it applies.
  • Thanks. It seems to be working but I will test the sub.

    I'm trying to set up a non-continental US/Canada shipping option but something is not right. IS there something is wrong with this:
    if (sub_tot < 10 && country_code == "US") { // less that $10 in US is 6.99
      var postage_usps = 6.99;
      addShippingOption(1, postage_usps, 'USPS', 'Standard');
      var postage_fast = 12.89; //priority shipping domestic
      addShippingOption(4, postage_fast, 'USPS', 'Priority');
    } else if (sub_tot >= 10 && country_code == "US") { // over 10 US is free
      addShippingOption(3, 0, '', 'Free Shipping');
    } else if (country_code == "CA" || state_code == "HI" || state_code == "AK") { // non-continental US and canada
      var postage_na = 13.95;
      addShippingOption(1, postage_na, 'USPS', 'Standard');
    } else if (country_code != "US") { //international is 29.90
      var postage_int = 29.95;
      addShippingOption(2, postage_int, 'USPS', 'International');
    }
    


  • fredfred FoxyCart Team
    edited December 2013
    Hey @mree, at first glance your code looks good, but I see a potential bug in your rule for Canadian/non-contiguous shipping. Change that test to:
    else if (country_code == "CA" || (country_code == "US" && (state_code == "HI" || state_code == "AK"))) {
    
    

    Can you test that change? If the issue's still happening after that, could you reply with some steps we can follow to reproduce the problem? Something like "entered this address for shipping, and got this X shipping rate but expected Y shipping rate" would help us sort things out more quickly.
  • @fred,

    Thanks for the help. So everything is working except the custom code for hawaii and alaska, they just stay on the normal US shipping.

    Set state to Hawaii and got 6.99/12.89 for shipping, expected 13.95.

  • fredfred FoxyCart Team

    Aha, just realized what the issue is. You're testing for Hawaii / Alaska AFTER you've tested for "in the US" free shipping. Move that test to the top:
    if (country_code == "CA" || (country_code == "US" && (state_code == "HI" || state_code == "AK"))) { // non-continental US and canada
      var postage_na = 13.95;
      addShippingOption(1, postage_na, 'USPS', 'Standard');
    } else if (sub_tot < 10 && country_code == "US") { // less that $10 in US is 6.99
      var postage_usps = 6.99;
      addShippingOption(1, postage_usps, 'USPS', 'Standard');
      var postage_fast = 12.89; //priority shipping domestic
      addShippingOption(4, postage_fast, 'USPS', 'Priority');
    } else if (sub_tot >= 10 && country_code == "US") { // over 10 US is free
      addShippingOption(3, 0, '', 'Free Shipping');
     else if (country_code != "US") { //international is 29.90
      var postage_int = 29.95;
      addShippingOption(2, postage_int, 'USPS', 'International');
    }
    

    I'm interpreting what you wanted as "$13.95 shipping to HI, AK, or Canada; FREE SHIPPING orders over $10 in the contiguous US; $6.99 to the US for orders under $10; and $29.90 for anyone else."

    Is that right?
  • Your explanation of the logic at the end is right. The shipping options section isn't showing up now but the code looks right. Not sure whats causing that
  • fc_adamfc_adam FoxyCart Team
    @mreee,

    Looks like Fred may have missed closing curly bracket in his changes in the previous post. Try this:
    if (country_code == "CA" || (country_code == "US" && (state_code == "HI" || state_code == "AK"))) { // non-continental US and canada
      var postage_na = 13.95;
      addShippingOption(1, postage_na, 'USPS', 'Standard');
    } else if (sub_tot < 10 && country_code == "US") { // less that $10 in US is 6.99
      var postage_usps = 6.99;
      addShippingOption(1, postage_usps, 'USPS', 'Standard');
      var postage_fast = 12.89; //priority shipping domestic
      addShippingOption(4, postage_fast, 'USPS', 'Priority');
    } else if (sub_tot >= 10 && country_code == "US") { // over 10 US is free
      addShippingOption(3, 0, '', 'Free Shipping');
    } else if (country_code != "US") { //international is 29.90
      var postage_int = 29.95;
      addShippingOption(2, postage_int, 'USPS', 'International');
    }
    
  • Thanks for the help @fc_adam.

    I ran a subscription through to test it and I am running in to the free shipping problem (in the last comment from the 4th).

    The free trial goes through with 6.99 shipping but then the recurring subscription is also charged shipping. I know you said that the shipping is set at the time of purchase since the shipping logic is run at the time of checkout. Is there any way to get around this?
  • @fc_adam,

    I tested the code you posted and the shipping options disappeared again. I left the logic in the checkout so you can view.
  • winstonwinston FoxyCart Team
    @mreee

    I'll try to help while @fc_adam is on the road! I just tested your checkout and it's throwing an error:

    Uncaught ReferenceError: state_code is not defined

    I think if you add this right after where you have var country_code in your template, it should help:
    var state_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_state").val());
    

    Test that and see if it resolves the issues!
  • @winston,

    That fixed it. Thank you for your help!
  • winstonwinston FoxyCart Team
    @mreee

    Awesome. Let us know if you run into other issues!
  • fc_adamfc_adam FoxyCart Team
    @mreee,

    At this stage - there would be a few ways you could clear out the shipping:

    Firstly, you can manually remove the shipping cost from a subscription by editing the subscription in the FoxyCart admin. If you only have a few orders, that can work pretty well.

    Secondly, you could do the above automatically using the API instead.
Sign In or Register to comment.