Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active February 17, 2022 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewlimaza/79f29484abd7713cf4de0e2cd6cdedae to your computer and use it in GitHub Desktop.
Save andrewlimaza/79f29484abd7713cf4de0e2cd6cdedae to your computer and use it in GitHub Desktop.
Show number of spots available for a membership level Paid Memberships Pro.
<?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