Skip to content

Instantly share code, notes, and snippets.

@messica
Created October 2, 2014 14:51
Show Gist options
  • Select an option

  • Save messica/2100a6d4375cf79a58a8 to your computer and use it in GitHub Desktop.

Select an option

Save messica/2100a6d4375cf79a58a8 to your computer and use it in GitHub Desktop.
Limit number of checkouts for a specific membership level
<?php
/*
* Limit checkouts for membership level
*/
function my_pmpro_registration_checks($continue_registration) {
global $wpdb;
$member_limit = 0; //max number of members for this level
$level_ids = array(1,2,3); //levels to apply this to
if(in_array($_REQUEST['level'], $level_ids)) {
//count active memberships for this level
$count = $wpdb->query("SELECT COUNT(*) FROM $wpdb->pmpro_memberships_users WHERE membership_id=" . $_REQUEST['level'] . " AND status='active'");
if($count >= $member_limit) {
$continue_registration = false;
pmpro_setMessage('The maximum number of members for this level has been reached.', 'pmpro_error');
}
}
return $continue_registration;
}
add_filter('pmpro_registration_checks', 'my_pmpro_registration_checks');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment