Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Last active July 16, 2019 14:00
Show Gist options
  • Save cartpauj/897ba2ab5dd7626861a80c75ff02b22a to your computer and use it in GitHub Desktop.
Save cartpauj/897ba2ab5dd7626861a80c75ff02b22a to your computer and use it in GitHub Desktop.
Limit MemberPress Signups to one Country
<?php
function limit_signups_to_one_country($errors) {
// Limit Signups to USA only
if(!isset($_POST['mepr-address-country']) || $_POST['mepr-address-country'] != 'US') {
$errors[] = 'Sorry, signups are currently limited to USA only.';
}
return $errors;
}
add_filter('mepr-validate-signup', 'limit_signups_to_one_country');
@cartpauj
Copy link
Author

cartpauj commented Jul 1, 2019

Multiple countries example

function limit_signups_to_one_country($errors) {
  $countries = array('AU', 'NZ');

  // Limit Signups to USA only
  if(!isset($_POST['mepr-address-country']) || !in_array($_POST['mepr-address-country'], $countries)) {
    $errors[] = 'Sorry, signups are currently limited to Australia and New Zeland only.';
  }

  return $errors;
}
add_filter('mepr-validate-signup', 'limit_signups_to_one_country');```

@cartpauj
Copy link
Author

cartpauj commented Jul 3, 2019

Removes countries from dropdown itself.

function filter_out_countries($countries, $prioritize_my_country) {
  $countries_to_keep = array('AU', 'NZ');

  foreach($countries as $code => $title) {
    if( ! in_array($code, $countries_to_keep) ) {
      unset($countries[$code]);
    }
  }

  return $countries;
}
add_filter('mepr_countries', 'filter_out_countries', 11, 2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment