Last active
August 15, 2024 19:22
-
-
Save dwanjuki/119eb34857e9de631b58b42188feb534 to your computer and use it in GitHub Desktop.
Require a group code to register for a 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 // copy from below | |
| /** | |
| * Only let level 2 members sign up if they use a Group code. | |
| * | |
| * You can add this recipe to your site by creating a custom plugin | |
| * or using the Code Snippets plugin available for free in the WordPress repository. | |
| * Read this companion article for step-by-step directions on either method. | |
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function my_pmpro_require_group_code_to_register( $pmpro_continue_registration ) { | |
| // If there is already a checkout error, bail. | |
| if ( ! $pmpro_continue_registration ) { | |
| return $pmpro_continue_registration; | |
| } | |
| // if level = 2 and there is no group code, then show an error message | |
| $pmpro_level = pmpro_getLevelAtCheckout(); | |
| if ( $pmpro_level->id == 2 && empty( $_REQUEST['pmprogroupacct_group_code'] ) ) { | |
| pmpro_setMessage("You must use a valid group code to register for this level.", "pmpro_error"); | |
| return false; | |
| } | |
| return $pmpro_continue_registration; | |
| } | |
| add_filter( 'pmpro_registration_checks', 'my_pmpro_require_group_code_to_register' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment