-
-
Save strangerstudios/76bd8643f60321b147d19b35c7bb0093 to your computer and use it in GitHub Desktop.
Restrict certain countries from signing up for certain 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
function my_init() | |
{ | |
global $restricted_countries; | |
//specify the countries not allowed to signup. The key is the level id. | |
$restricted_countries = array( | |
1 => array('FR', 'IT'), | |
2 => array('IT'), | |
); | |
} | |
add_action('init', 'my_init'); | |
function my_pmpro_registration_checks($value) | |
{ | |
global $restricted_countries, $pmpro_msg, $pmpro_msgt; | |
$country = $_REQUEST['bcountry']; | |
$level_id = $_REQUEST['level']; | |
//only check if the level has restrictions | |
if(array_key_exists($level_id, $restricted_countries) && in_array($country, $restricted_countries[$level_id])) | |
{ | |
$pmpro_msg = "Your country of residence is not permitted to register for this level."; | |
$pmpro_msgt = "pmpro_error"; | |
$value = false; | |
} | |
return $value; | |
} | |
add_filter("pmpro_registration_checks", "my_pmpro_registration_checks"); | |
function my_pmpro_level_expiration_text($text, $level) | |
{ | |
global $restricted_countries, $pmpro_countries; | |
if(array_key_exists($level->id, $restricted_countries )) | |
{ | |
$text = $text." This level cannont be purchased if you reside in the following countries: "; | |
//code for commas | |
$i = 1; | |
foreach($restricted_countries[$level->id] as $country) | |
{ | |
$text = $text. $pmpro_countries[$country]; | |
if($i != count($restricted_countries[$level->id])) | |
$text = $text. ", "; | |
$i++; | |
} | |
} | |
return $text; | |
} | |
add_filter("pmpro_level_expiration_text", "my_pmpro_level_expiration_text", 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Restrict Membership Signup by Country" at Paid Memberships Pro here: https://www.paidmembershipspro.com/restrict-membership-signup-country/