Skip to content

Instantly share code, notes, and snippets.

@kloon
Last active December 22, 2015 23:39
Show Gist options
  • Save kloon/6548151 to your computer and use it in GitHub Desktop.
Save kloon/6548151 to your computer and use it in GitHub Desktop.
WooCommerce limit total purchased product quantity based on group. Allows customer to only check out when total product quantity are a certain step
<?php
add_action( 'woocommerce_check_cart_items', 'wc_limit_total_products_purchased_check' );
function wc_limit_total_products_purchased_check() {
global $woocommerce;
$step = 40;
$total_items = $woocommerce->cart->get_cart_contents_count();
if ( $total_items % $step )
$woocommerce->add_error( sprintf( __( 'Your must purchase in groups of %s products, please add or remove products to continue.', 'woocommerce' ), $step ) );
}
?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment