Created
February 13, 2014 05:42
-
-
Save meishern/8970339 to your computer and use it in GitHub Desktop.
WooCommerce Check Cart Quantity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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