limit number of subscribers
-
on github there’s this code to limit the number of subscribers for limit.
I added it in PMPro Customizations.
I’ve two problems
1) on page doesn’t show “2/10 spots available” (i.e.).
2) when I punt to 0 the limit of subscription available the button [pmpro_checkout_button class=”pmpro_btn” level=”X” text=”BUY”] still works.
-
Hi @plxmas
Thank you for using Paid Memberships Pro.
This code snippet does not show the number of available spots but will run during the registration process and if there are no spots left for this level it will show an error message and stop the registration from proceeding.
You will need to use this functionality alongside the gist you’ve mentioned – https://gist.github.com/kimcoleman/51c03c3ec77ab84713dc80a512225f11#file-pmpro_show_spots_available-php
To disable signups, please set the “Disable New Signups” setting inside the level settings area instead.
If you need further assistance regarding these code snippets, please open a support ticket on https://www.paidmembershipspro.com.
I hope this helps get you started.
I’ve added the code you linked in your reaply at bottom of previous code in pmpro-customizations.php and it doesn’t show “2/10 spots available” (i.e.)
may I need to insert a shortcode ?
and why when I put the limit to 0 the button “buy” still work? I expect that, if I put to 0 the number of subscription available it doesn’t work.
<?php /* Plugin Name: PMPro Customizations Plugin URI: https://www.paidmembershipspro.com/wp/pmpro-customizations/ Description: Customizations for my Paid Memberships Pro Setup Version: .1 Author: Paid Memberships Pro Author URI: https://www.paidmembershipspro.com */ //Now start placing your customization code below this line /* Set a maximum number of members allowed to register for a membership level. Add this code to a plugin for PMPro Customizations. Set the "Maximum" for a level on the Memberships > Membership Levels > Edit Level admin page. */ function pmproml_pmpro_save_membership_level( $level_id) { if( $level_id <= 0 ) { return; } $limit = $_REQUEST['pmpro_member_limit']; update_option('pmpro_limit_'.$level_id, $limit); } add_action( 'pmpro_save_membership_level', 'pmproml_pmpro_save_membership_level' ); function pmproml_pmpro_membership_level_after_other_settings ( ) { ?> <h3 class="topborder"><?php _e('Membership Limits', 'paid-memberships-pro');?></h3> <table class="form-table"> <tbody> <tr> <th scope="row" valign="top"><label for="pmpro_member_limit"><?php _e('Maximum', 'paid-memberships-pro'); ?></label></th> <td> <?php if( isset( $_REQUEST['edit'] ) ) { $edit = intval( $_REQUEST['edit'] ); $limit = get_option( 'pmpro_limit_' . $edit ); } else { $limit = ""; } ?> <input type="text" name="pmpro_member_limit" id="pmpro_member_limit" size="6" value="<?php echo $limit; ?>" /> <p class="description"><?php _e('Set the maximum number of members for this level.', 'paid-memberships-pro'); ?></p> </td> </tr> </tbody> </table> <?php } add_action( 'pmpro_membership_level_after_other_settings', 'pmproml_pmpro_membership_level_after_other_settings' ); function pmproml_pmpro_registration_checks( $value ) { global $wpdb; $level_id = intval( $_REQUEST['level'] ); //get the maximum number of members allowed in this level $limit = get_option( 'pmpro_limit_' . $level_id ); //get the count of members in this level $sql = "SELECT COUNT(*) FROM {$wpdb->pmpro_memberships_users} WHERE <code>status</code> LIKE 'active' AND <code>membership_id</code> = ". esc_sql($level_id); $member_count = $wpdb->get_var($sql); //compare the count of members to the maximum number of members allowed in this level if($member_count >= $limit) { global $pmpro_msg, $pmpro_msgt; $pmpro_msg = __('Membership limit has been reached for this level', 'paid-memberships-pro'); $pmpro_msgt = "pmpro_error"; $value = false; } return $value; } add_filter( 'pmpro_registration_checks', 'pmproml_pmpro_registration_checks' ); /* * 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 <code>status</code> LIKE 'active' AND <code>membership_id</code> = ". 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 );
-
This reply was modified 3 years, 6 months ago by
plxmas.
To disable the signup, please do not set 0 as the limit. You may set the “Disable New Signups” option within that level instead – this will prevent new user’s from purchasing this level.
I have retested this code and it works as intended. The available spots show inside the level description:
If you need assistance to get this custom code snippet working on your site, please reach out to https://www.paidmembershipspro.com and someone from our team will be able to assist you further.
ah ok, it appears in level description (after you click on button “buy”).
if I want to show near “buy” button i made with shortcode?
I set to 10 the number of place available.
it shows to me 12/10 spots available.It is showing 12/10 as I am assuming you already have members belonging to this level. This code snippet takes pre-existing members into account.
You may be able to tweak this code snippet further to only consider members from a specific date.
To move this closer to the “buy” button, you would need to tweak the ‘pmpro_level_description’ function to hook into ‘pmpro_checkout_before_submit_button’ and rework the logic in the function to echo this out -https://www.paidmembershipspro.com/hook/pmpro_checkout_before_submit_button/
Please note that our support does not cover customization requests of this nature and it would be best to reach out to a local WordPress developer or https://jobs.wordpress.net for assistance in customizing your checkout process.
I hope this helps get you started. Thank you for understanding.
-
This reply was modified 3 years, 6 months ago by
- The topic ‘limit number of subscribers’ is closed to new replies.