In Woocommerce, I would like to set some requirements to be approved before customer to be able to checkout. I would like customer to have quantity of 6 before they can proceed to checkout.
Quantity is not related just to one product, they can combine more products until they reach total quantity.
If have exactly 6 , then can proceed. Next stage, must have exactly 12 quantity before can checkout (if have 8 quantity in cart for example), after that 18, 24 etc....
I am using this function, that works just for 6 items quantity count limitation. I would like too extend the functionality with the logic explained before, making it dynamic and progressive.
My actual code:
// Set a minimum number of products requirement before checking out
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 = 6;
// Get the Cart's total number of products
$cart_num_products = WC()->cart->cart_contents_count;
// Compare values and add an error is Cart's total number of products
// happens to be less than the minimum required before checking out.
// Will display a message along the lines of
// A Minimum of 20 products is required before checking out. (Cont. below)
// Current number of items in the cart: 6
if( $cart_num_products < $minimum_num_products ) {
// Display our error message
wc_add_notice( sprintf( '<strong>A Minimum of %s products is required before checking out.</strong>'
. '<br />Current number of items in the cart: %s.',
$minimum_num_products,
$cart_num_products ),
'error' );
}
}
}
Any help will be really appreciated.