Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/62eede2857246d7bd182704bb42b7ba6 to your computer and use it in GitHub Desktop.
Save kimwhite/62eede2857246d7bd182704bb42b7ba6 to your computer and use it in GitHub Desktop.
Require a group code to register for a level
<?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