Minimum Number Of Products Required For Per Order

A minimum number of products that have to be ordered at a time before allowing the customer to fully pay for his order and shipped. Change ’5’ to whatever works best for your needs.

How to use it
This is example for set minimum product is 5.





add_action( 'woocommerce_check_cart_items', 'spyr_set_min_num_products' );
function spyr_set_min_num_products() {
	// Only run in the Cart or Checkout pages
	if( is_cart() || is_checkout() ) {
		global $woocommerce;

		// Set the minimum number of products before checking out
		$minimum_num_products = 5;
		// Get the Cart's total number of products
		$cart_num_products = WC()->cart->cart_contents_count;

		
		if( $cart_num_products < $minimum_num_products ) {
			// Display our error message
	        wc_add_notice( sprintf( 'A Minimum of %s products is required before checking out.' 
	        	. '
Current number of items in the cart: %s.',
	        	$minimum_num_products,
	        	$cart_num_products ),
	        'error' );
		}
	}
}

Advertisements