This code allows you to limit purchases to a multiple of products. For example, if you are selling wine you might only allow sales by the case or half case (so a multiple of 6 bottles).
/**
* Set an order quantity multiple for checkout
*/
add_action('woocommerce_checkout_process', 'cc_order_quantity_multiple');
add_action('woocommerce_before_cart', 'cc_order_quantity_multiple');
function cc_order_quantity_multiple() {
// Set this variable to specify an order quantity multiple
$multiple = 6;
if ((WC()->cart->get_cart_contents_count() % $multiple) > 0) {
if(is_cart()) {
remove_action('woocommerce_proceed_to_checkout','woocommerce_button_proceed_to_checkout', 20);
wc_print_notice(sprintf('You must place an order with a multiple of 6 items'), 'error');
} else {
remove_action('woocommerce_proceed_to_checkout','woocommerce_button_proceed_to_checkout', 20);
wc_add_notice(sprintf('You must place an order with a multiple of 6 items'), 'error');
}
}
}
View Raw
Code ID: 91093