Last active
February 17, 2022 11:39
-
-
Save andrewlimaza/79f29484abd7713cf4de0e2cd6cdedae to your computer and use it in GitHub Desktop.
Show number of spots available for a membership level Paid Memberships Pro.
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 | |
/** | |
* This will show '0/X spots available.' on membership level description if a limit is set from (https://www.paidmembershipspro.com/limit-number-members-membership-level/) | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* For help, post a support thread on www.paidmembershipspro.com | |
*/ | |
function pmpro_show_spots_available( $description, $level ) { | |
global $wpdb; | |
$level_id = intval( $level->id ); | |
//get the maximum number of members allowed in this level | |
$limit = get_option( 'pmpro_limit_' . $level_id ); | |
// if the limit is not set, just return the default description for that level. | |
if( empty( $limit ) ){ | |
return $description; | |
} | |
//get the count of members in this level | |
$sql = "SELECT COUNT(*) | |
FROM {$wpdb->pmpro_memberships_users} | |
WHERE `status` = 'active' AND `membership_id` = ". esc_sql($level_id); | |
$member_count = $wpdb->get_var($sql); | |
$description .= $member_count . '/' . $limit; | |
$description .= ' spots available.'; | |
return $description; | |
} | |
add_filter( 'pmpro_level_description', 'pmpro_show_spots_available', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment