Created
October 2, 2014 14:51
-
-
Save messica/2100a6d4375cf79a58a8 to your computer and use it in GitHub Desktop.
Limit number of checkouts for a specific membership level
This file contains hidden or 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
| <?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