Free Shipping Coupon

ahsodesignsahsodesigns Member
in Help edited November 2014
We're needing to add a coupon that offers free shipping for orders totaling over $50 AND are being shipped to a single address.
https://wiki.foxycart.com/snippets/shipping/free_shipping_using_a_coupon gets me part of the way there but I can't get the over $50 part to work. Set the coupon discount type to 'Discount by an amount based on the price...' and the coupon details to '50-0' but it's still showing up for orders below that total price.

Then is there any way to make sure the order is not using multi-ship to complete the validation of the coupon code?

Thanks!
Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @ahsodesigns,

    Even though the coupon doesn't apply yet - it will still be present in the JSON cart object, which is all that the snippet is checking for, it's presence.

    What you'll want to do is add your total price check as part of the free shipping logic as well. So for example, you could expand this line from the snippet:
    if(coupon.name.search(/free shipping/i) > -1) {
    

    To instead be this:
    if(coupon.name.search(/free shipping/i) > -1 && fc_json.total_item_price >= 50) {
    

    That will only run the code following if the free shipping coupon is present, and the total item price in the cart is equal to or greater than 50
  • Ok. That makes sense. Thanks!
  • PasqualePasquale Member
    edited November 2014
    @fc_adam,

    Using 2.0 - I have been trying to set this exact method up with not much luck ( I am sure I am missing something.)

    I am looking to offer free shipping with a purchase of $50 or more.
    FC.customLiveShipping.hide('free');
    if(!jQuery.isEmptyObject(FC.json.coupons)) {
    	jQuery.each(FC.json.coupons, function(i, coupon){
    if(coupon.name.search(/free shipping/i) > -1 && fc_json.total_item_price >= 50) {
    			FC.customLiveShipping.show('free');
    		}
    	});
    }
    

    (note: Also, with the JS added to the footer in the template, the side cart goes full page?)

    Live store http://www.martinranchwinery.com/wine-shop/
  • fc_adamfc_adam FoxyCart Team
    @Pasquale,

    As you're on 2.0 - you'll need to use a slightly different conditional there, like this:
    FC.json.total_item_price >= 50
    
  • PasqualePasquale Member
    edited November 2014
    @fc_adam, Thanks for checking in! Sorry to bug you so close to the holidays... Unfortunately adding the conditional did not work... and the side cart goes full page.

    I have been following along in the 2.0 wiki
    https://wiki.foxycart.com/v/2.0/snippets/live_rate_shipping_modification

    I am looking at hiding the free ground shipping, if the freeshipping coupon is present and they spend $50 or more, the free shipping appears.

    Live store http://www.martinranchwinery.com/wine-shop/
  • fc_adamfc_adam FoxyCart Team
    edited November 2014
    @Pasquale,

    Could you post the code you're including? The custom logic should be almost identical to above, except with that one change - so it would look like this:

    [edit] Actually - as you've renamed the free ground shipping option, the "free" string won't find it. Try this:
    FC.customLiveShipping.hide(60);
    if(!jQuery.isEmptyObject(FC.json.coupons)) {
        jQuery.each(FC.json.coupons, function(i, coupon){
            if(coupon.name.search(/free shipping/i) > -1 && FC.json.total_item_price >= 50) {
                FC.customLiveShipping.show(60);
            }
        });
    }
    

    When you have the code added - if it still redirects to the full page cart, do you see any errors in your browsers console log?
  • @fc-adam,

    This morning I went back to the default "free ground shipping" with no luck so I changed it back to "Complimentary Shipping" (Wineries cannot offer free shipping). That said, I tried the above and it did not hide/show the shipping with $50.

    I can leave the code in place until tomorrow if your still working... which you should not be like me :)

    There are console errors :
    [Error] Viewport argument key "minimal-ui" not recognized and ignored. (cart, line 9)
    [Error] SyntaxError: Unexpected end of script
    	(anonymous function) (cart, line 540)
    
  • fc_adamfc_adam FoxyCart Team
    @Pasquale,

    I'm based in Australia, so today is just a normal Thursday for me :) I'll take a quick look and get back to you as soon as I can - thanks for leaving the script in place.
  • fc_adamfc_adam FoxyCart Team
    @Pasquale,

    I think I've got it - the snippet is missing a closing bracket for the logic function.

    After this line:
    /* END CUSTOM SHIPPING LOGIC */
    


    Add this:
    };
    
  • Your above and beyond... Many thanks! I'll be on :)
  • fc_adamfc_adam FoxyCart Team
    @Pasquale,

    Looks like we responded at the same time - just pinging you to ensure you saw my response above.
  • PasqualePasquale Member
    edited November 2014
    @fc-adam, Yes I am on with you


    - good catch! OK side cart is working as expected...

    1) Complimentary shipping (is checked on in the shipping settings)

    2) Complimentary shipping does not show in the cart

    3) When adding "freeshipping" coupon - Complimentary shipping does not appear.

  • fc_adamfc_adam FoxyCart Team
    edited November 2014
    @Pasquale,

    Looking at the store's coupons - I'm not seeing one that has "free shipping" in it's name. The logic is looking for a coupon to be present in the cart that has "free shipping" within the name (case insensitive).

    You can change that to match the name of the coupon you have by changing the "free shipping" text in the logic.
  • @fc_adam,

    Coupon Name: Weekend Round Up

    Coupon Codes: 1. freeshipping

    Will this work?
  • PasqualePasquale Member
    edited November 2014
    @fc_adam, I have troubleshoot to match names with no luck.

    Right now I renamed to compship ( see code below) - and do not see the complimentary shipping option appear.
    Coupon Name: CompShip
    
    Coupon Codes:  1.CompShip
    
    FC.customLiveShipping.hide(60);
    if(!jQuery.isEmptyObject(FC.json.coupons)) {
        jQuery.each(FC.json.coupons, function(i, coupon){
            if(coupon.name.search(/compship/i) > -1 && FC.json.total_item_price >= 50) {
                FC.customLiveShipping.show(60);
            }
        });
    }
    
  • fc_adamfc_adam FoxyCart Team
    @Pasquale,

    I just tested this - and it's working fine for me. You're perhaps running a stale version of the javascript that isn't using your newest change. Could you try refreshing your page and give it another try?
  • @fc_adam, Using the latest Safari, I had clear the cache and refreshed with no luck. So I switched to Chrome and Viola! Its working as expected...

    Other then rest... Is there anything else I need to do?

    Many thanks!
  • fc_adamfc_adam FoxyCart Team
    @Pasquale,

    If it's working as you're wanting it to - then you're all good!
  • @fc_adam,

    Yes - tested out and working... Thanks for the great help!
Sign In or Register to comment.