Setting a minimum order for the total cart

davidzupecdavidzupec Member
in Help edited May 2014
Hello, my clients store is selling 2 products. They want to be able to set a minimum order of 2 for the total cart contents. For example the customer could order 1 of each or 2 of the same product. Is this possible?

Than you!
Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @davidzupec,

    It is - and you'd achieve it with javascript on your cart and checkout templates. What you'd do is put in some logic that checks the JSON cart object, and if the total items is less than 2, prevent the customer from being able to complete the checkout. On the cart, you would do that with this line:
    fc_PreventCheckout()
    

    And on the checkout, like this:
    FC.checkout.config.isValid = false;
    
  • Hi Adam, below is what I have but I can't figure out what is wrong!

    In the cart:
    <script type="text/javascript" charset="utf-8">
    
    function cart_quantity_check() {
    // remove checkout if less than 2
    if (fc_json.total_quantity < 2) {
    fc_PreventCheckout();
    // Display a notification message
    var noticeText = "Please order 2 items or more.";
    if ($('#fc_error_container ul li').length) {
          jQuery("#fc_error_container ul").append("<li>"+noticeText+"</li>");
        } else {
          jQuery("table#fc_cart_table").before("<div id=\"fc_message_container\"><div id=\"fc_error_container\" class=\"fc_message fc_error\"><ul><li>"+noticeText+"</li></ul></div></div>");
        }
    }
    }
    $(document).ready(function(){
    // The setTimeout gets around a Thickbox issue.
    setTimeout("cart_quantity_check()", 0);
    });
    
    </script>
    

    And in my checkout template:
    <script type="text/javascript">
    		FC.checkout.config.isValid = false;
    	</script>
    
  • fc_adamfc_adam FoxyCart Team
    @davidzupec,

    Your checkout template would need the same logic to check the quantity - with you just setting it to false straight away, that will just prevent everyone from being able to check out.

    In your cart logic - all that is wrong there is the JSON you want is fc_json.product_count. Everything else looks to be spot on.
  • Hey Adam, great thank you! Would I even need that additional logic on the checkout template? Because if they order less than 2 the cart spits out the error message and the checkout button is disabled so they can't proceed to the checkout page anyway until they change the quantity.

    Thank you again!
  • fc_adamfc_adam FoxyCart Team
    @davidzupec,

    You don't - as long as there is no way that the customer would skip the checkout - for example if you have a cart=checkout call somewhere on your site, they'd completely miss the cart.
  • Hi Adam, yeah there's no other cart checkout calls on the site. That's good to know, thank you very much for your help!!!
  • Hi Guys,

    I'm looking to do the exact same thing except set it for 6 products. Would this snippet work for version 2.0?

    Thanks for any help!
  • fc_adamfc_adam FoxyCart Team
    @myaleigh,

    It would need to be a different snippet for 2.0. Something like this should cover what you're after, paste this in the "footer" textarea for the "Add custom header/footer code" configuration option for your store.
    <script>FC.client.on("ready.done", quantityCallback);
    FC.client.on("cart-submit.done", quantityCallback);
    FC.client.on("cart-item-quantity-update.done", quantityCallback);
    FC.client.on("cart-item-remove.done", quantityCallback);
    
    function quantityCallback() {
    	var min_quantity = 6;
    	var min_quantity_message = "A minimum of 6 products is required to checkout";
    	if (FC.json.context == "cart") {
    		if (FC.json.item_count < min_quantity) {
    			if (jQuery(".min-quantity").length == 0) {
    				jQuery(".fc-actions--payment").prepend("<p class='min-quantity'>" + min_quantity_message + "</p>");
    			}
    			jQuery(".fc-actions--payment").children().hide();
    			jQuery(".min-quantity").show();
    		} else {
    			jQuery(".fc-actions--payment").children().show();
    			jQuery(".min-quantity").hide();
    		}
    	} else if (FC.json.context == "checkout") {
    		if (FC.json.item_count < min_quantity) {
    			if (jQuery(".min-quantity").length == 0) {
    				jQuery(".fc-container__grid--checkout-submit").prepend("<p class='min-quantity'>" + min_quantity_message + "</p>");
    			}
    			jQuery(".fc-button--submit").hide();
    			jQuery(".min-quantity").show();
    		} else {
    			jQuery(".fc-button--submit").show();
    			jQuery(".min-quantity").hide();
    		}
    	}
    }</scriot>
    
Sign In or Register to comment.