Skip to content

Instantly share code, notes, and snippets.

@meishern
Created February 13, 2014 05:42
Show Gist options
  • Save meishern/8970339 to your computer and use it in GitHub Desktop.
Save meishern/8970339 to your computer and use it in GitHub Desktop.
WooCommerce Check Cart Quantity
// check that cart items quantities totals are in multiples of 5
add_action( 'woocommerce_check_cart_items', 'woocommerce_check_cart_quantities' );
function woocommerce_check_cart_quantities() {
global $woocommerce;
$multiples = 5;
$total_products = 0;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$total_products += $values['quantity'];
}
if ( ( $total_products % $multiples ) > 0 )
$woocommerce->add_error( sprintf( __('You need to buy in quantities of %s products', 'woocommerce'), $multiples ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment