Created
June 8, 2021 15:37
-
-
Save dparker1005/e0388539f906e5a09cc1746908311a13 to your computer and use it in GitHub Desktop.
Require user to confirm there email address before checking out for specific levels.
This file contains 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 | |
/* | |
* Require user to confirm there email address before checking out for specific levels. | |
* Can build a free level requiring email confirmation for users to sign up for before the "real" levels. | |
* | |
* 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_email_confirmation_for_checkout( $okay ) { | |
$confirmation_levels = array( 1 ); // Email confirmation is required before purchasing one of these memberhsip levels. | |
global $pmpro_level, $current_user; | |
if ( $okay && in_array( intval( $pmpro_level->id ), $confirmation_levels ) ) { | |
if ( empty( $current_user->ID ) ) { | |
pmpro_setMessage("You must register for the free membership level and confirm your email address before purchasing this memberhsip level.", "pmpro_error"); | |
$okay = false; | |
} else { | |
//if they haven't validated yet, don't let them check out | |
$validation_key = get_user_meta( $current_user->ID, "pmpro_email_confirmation_key", true ); | |
if ( $validation_key !== 'validated' ) { | |
pmpro_setMessage("You must register for the free membership level and confirm your email address before purchasing this memberhsip level.", "pmpro_error"); | |
$okay = false; | |
} | |
} | |
} | |
return $okay; | |
} | |
add_action("pmpro_registration_checks", "my_pmpro_require_email_confirmation_for_checkout"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment