A simple, powerful and independent e-commerce platform.
Sell anything with ease.

Set a minimum order quantity for checkout

This code sets a minimum order quantity before checkout is allowed to proceed. The checkout button is hidden and an error message is displayed. This example sets the minimum order to 12. The error message can be edited to suit.

/**
 * Set a minimum order quantity for checkout
 */

add_action('woocommerce_checkout_process', 'cc_minimum_order_quantity');
add_action('woocommerce_before_cart', 'cc_minimum_order_quantity');

function cc_minimum_order_quantity() {

  // Set this variable to specify a minimum order quantity
  $minimum = 12;

  if (WC()->cart->get_cart_contents_count() < $minimum) {

    if(is_cart()) {

      remove_action('woocommerce_proceed_to_checkout','woocommerce_button_proceed_to_checkout', 20);
      wc_print_notice(sprintf('You must have an order with a minimum of 12 items'), 'error');

    } else {

      remove_action('woocommerce_proceed_to_checkout','woocommerce_button_proceed_to_checkout', 20);
      wc_add_notice(sprintf('You must have an order with a minimum of 12 items'), 'error');

    }
  }
}
View Raw Code ID: 1090