Forked from dwanjuki/my_pmpro_require_group_code_to_register.php
Last active
October 29, 2024 17:39
-
-
Save kimwhite/62eede2857246d7bd182704bb42b7ba6 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 | |
/** | |
* Set multiple levels to require 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; | |
} | |
// Array of Level IDs that require a group code | |
$required_levels = array(2,3, 5); // Replace these with the level IDs you want to require a group code | |
// Get the current level at checkout | |
$pmpro_level = pmpro_getLevelAtCheckout(); | |
// Check if the level requires a group code and if the group code is empty | |
if ( in_array( $pmpro_level->id, $required_levels ) && 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