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.

[SOLVED] Quantity Discount Help, Free Shipping if Quantity is more than X

AdamWintleAdamWintle Member
in Help edited August 2008
Hi everyone,

I'm building a store for an Australian clothes company which requires a couple of special features - first I've work with FoxyCart's Brett to get different shipping rates depending on which country your from, the code as follows:
<script type="text/javascript" charset="utf-8">
function fc_UpdatePrice() {
       fc_UpdatePaymentDisplay();
       return true;
}

function fc_UpdateShipping() {
       if ($j('#use_different_addresses').is(':checked')) {
               if ($j('#shipping_country').val() == 'AU' ) {
                       $j('#shipping_cost').val('6.00');
                       $j('#fc_cart_foot_shipping').html('AU$6.00');
                       $j('#shipping_note').html('Shipping to Australia.');
               } else {
                       $j('#shipping_cost').val('12.00');
                       $j('#fc_cart_foot_shipping').html('AU$12.00');
                       $j('#shipping_note').html('Shipping outside of Australia.');
               }
       } else {
               if ($j('#customer_country').val() == 'AU' ) {
                       $j('#shipping_cost').val('6.00');
                       $j('#fc_cart_foot_shipping').html('AU$6.00');
                       $j('#shipping_note').html('Shipping to Australia.');
               } else {
                       $j('#shipping_cost').val('12.00');
                       $j('#fc_cart_foot_shipping').html('AU$12.00');
                       $j('#shipping_note').html('Shipping outside of Australia.');
               }
       }
       var order_total_temp = parseFloat($j('#shipping_cost').val()) + parseFloat($j('#subtotal').val());
       $j('#order_total').val(order_total_temp.toFixed(2));
       $j('#fc_cart_foot_total').html('AU$' + order_total_temp.toFixed(2));

}
$j(document).ready(function(){
       $j('#li_subtotal_shipping_cost').after('<span id="shipping_note"><\/span>');
       fc_UpdateShipping();
});
</script>
This JavaScript is inserted straight after the ^^cart^^ and ^^checkout^^ on the checkout template - when the customer changes their shipping address to outside of Australia the shipping goes up from $6 to $12.

However, I'm trying to make a super-ship discount when a customer buys more than four items and they live in Australia their shipping is free - can anyone help me add this to the code?
Comments
  • brettbrett FoxyCart Team
    Mallmus, I know you figured this out so I'm noting it here. Feel free to post the new code if you want.
  • AdamWintleAdamWintle Member
    edited August 2008
    This seemed to do the trick:
    <script type="text/javascript" charset="utf-8">
    function fc_UpdatePrice() {
           fc_UpdatePaymentDisplay();
           return true;
    }
    
    function fc_UpdateShipping() {
    		var quantities = document.getElementById( "fc_cart_table" ).getElementsByTagName( "td" );
    		var totalQuantities = 0;
    		for ( var n = 0; n < quantities.length; n++ ) {
    			if ( quantities[n].className == "fc_cart_item_quantity" )
    				totalQuantities += parseInt( quantities[n].firstChild.data );
    		}
           if ($j('#use_different_addresses').is(':checked')) {
                   if ( ( $j('#shipping_country').val() == 'AU' ) && ( totalQuantities >= 4 ) ) {
                           $j('#shipping_cost').val('0.00');
                           $j('#fc_cart_foot_shipping').html('AU$0.00');
                           $j('#shipping_note').html('Shipping to Australia.');
                   }
                   else if ( $j('#shipping_country').val() == 'AU' ) {
                           $j('#shipping_cost').val('6.00');
                           $j('#fc_cart_foot_shipping').html('AU$6.00');
                           $j('#shipping_note').html('Shipping to Australia.');
                   }
                   else {
                           $j('#shipping_cost').val('12.00');
                           $j('#fc_cart_foot_shipping').html('AU$12.00');
                           $j('#shipping_note').html('Shipping outside of Australia.');
                   }
           } else {
                   if ( ( $j('#customer_country').val() == 'AU' ) && ( totalQuantities >= 4 ) ) {
                           $j('#shipping_cost').val('0.00');
                           $j('#fc_cart_foot_shipping').html('AU$0.00');
                           $j('#shipping_note').html('Shipping to Australia.');
                   }
                   else if ($j('#customer_country').val() == 'AU' ) {
                           $j('#shipping_cost').val('6.00');
                           $j('#fc_cart_foot_shipping').html('AU$6.00');
                           $j('#shipping_note').html('Shipping to Australia.');
                   }
                   else {
                           $j('#shipping_cost').val('12.00');
                           $j('#fc_cart_foot_shipping').html('AU$12.00');
                           $j('#shipping_note').html('Shipping outside of Australia.');
                   }
           }
           var order_total_temp = parseFloat($j('#shipping_cost').val()) + parseFloat($j('#subtotal').val());
           $j('#order_total').val(order_total_temp.toFixed(2));
           $j('#fc_cart_foot_total').html('AU$' + order_total_temp.toFixed(2));
    
    }
    $j(document).ready(function(){
           $j('#li_subtotal_shipping_cost').after('<span id="shipping_note"><\/span>');
           fc_UpdateShipping();
    });
    </script>
    

    This will give the customer free shipping if they buy four items or more and live in Austria. Feel free to ask any questions...
  • Very cool, but how about a simple shipping discount for a site that just ships within the U.S.?
    Example: Free shipping on orders over $75
    How would I implement that?

    Thanks
  • brettbrett FoxyCart Team
    Start with changing the AU to US, stick it in Firebug's js console and put something on your desk so you don't hurt your head as you get frustrated ;)

    Does that help? Give it a go and if you get stuck let us know.
  • I know my way around a web page, but I'm a genuine JS n00b. But, if I were brave and I wanted to use the script above, exactly where do I put that text so it so that it would be installed correctly and do its thing?

    Thanks!
    -Windell
  • In my situation, I tried to modify the script so that any order being shipped to the US and with a quantity of 2 or greater gets free shipping. However, the code isn't functioning. I inserted it directly after ^^checkout^^. Why isn't this working:

    <script type="text/javascript" charset="utf-8">
    function fc_UpdatePrice() {
    fc_UpdatePaymentDisplay();
    return true;
    }

    function fc_UpdateShipping() {
    var quantities = document.getElementById( "fc_cart_table" ).getElementsByTagName( "td" );
    var totalQuantities = 0;
    for ( var n = 0; n < quantities.length; n++ ) {
    if ( quantities[n].className == "fc_cart_item_quantity" )
    totalQuantities += parseInt( quantities[n].firstChild.data );
    }
    if ($j('#use_different_addresses').is(':checked')) {
    if ( ( $j('#shipping_country').val() == 'US' ) && ( totalQuantities >= 2 ) ) {
    $j('#shipping_cost').val('0.00');
    $j('#fc_cart_foot_shipping').html('$0.00');
    $j('#shipping_note').html('Free USPS Shipping');
    }
    else if ( $j('#shipping_country').val() == 'US' ) {
    $j('#shipping_cost').val('4.95');
    $j('#fc_cart_foot_shipping').html('$4.95');
    $j('#shipping_note').html('USPS Priority Mail');
    }

    } else {
    if ( ( $j('#customer_country').val() == 'US' ) && ( totalQuantities >= 2 ) ) {
    $j('#shipping_cost').val('0.00');
    $j('#fc_cart_foot_shipping').html('$0.00');
    $j('#shipping_note').html('Free USPS Shipping');
    }
    else if ($j('#customer_country').val() == 'US' ) {
    $j('#shipping_cost').val('4.95');
    $j('#fc_cart_foot_shipping').html('$4.95');
    $j('#shipping_note').html('USPS Priority Mail');
    }

    }
    var order_total_temp = parseFloat($j('#shipping_cost').val()) + parseFloat($j('#subtotal').val());
    $j('#order_total').val(order_total_temp.toFixed(2));
    $j('#fc_cart_foot_total').html('$' + order_total_temp.toFixed(2));

    }
    $j(document).ready(function(){
    $j('#li_subtotal_shipping_cost').after('<span id="shipping_note"><\/span>');
    fc_UpdateShipping();
    });
    </script>
  • lukeluke FoxyCart Team
    @paradiseroasters: what you're trying to accomplish is something we don't currently support, unfortunately. Are you using 032 or 050? All of the method names you have there appear to be from version 032 last year which is a couple versions out of date. In 040 we introduced the FC namespace and FC.checkout.overload and FC.checkout.override. Those are two (currently undocumented) methods that may enable you to override some built in functionality, but again, they are not currently supported. If you search through the comments in the forum, you may find a few examples of the usage, but we plan on reorganizing the checkout javascript at some point so anything we customize right now will have to remain unsupported.

    For support of what you're trying to do, please vote for supership here: http://requests.foxycart.com/
  • brettbrett FoxyCart Team
    Well... not _entirely_ undocumented, but definitely unsupported:
    http://wiki.foxycart.com/docs:checkout:javascript
  • lukeluke FoxyCart Team
    Huh... didn't realize we documented that. It will change in future versions, as will the methods used. Hopefully that doesn't cause too many problems for people down the road.
Sign In or Register to comment.