
Chazie Baniquid
Technical Content Marketer
8 minutes to read
How to block countries in Paid Memberships Pro?
Do you want to prevent users from certain countries from signing up for your membership site? If you’re using Paid Memberships Pro (PMPro), there’s no built-in setting to block countries, but you can still do it effectively.
In this guide, we’ll show you two methods:
- A custom code recipe that restricts registration by country for specific membership levels
- A plugin-based approach using OOPSpam Anti-Spam (that’s us 👋), ideal for blocking form submissions and spammy registrations
No Built-In Country Blocking in PMPro
Paid Memberships Pro doesn’t offer a built-in geolocation filter to restrict countries during the registration process. However, since the plugin is developer-friendly, it allows you to add a custom PHP filter that blocks registrations based on the user’s billing country.
Let’s explore your options.
1. Restrict Registrations by Country in Paid Memberships Pro (Code Method)
If you need to restrict membership signups from specific countries, PMPro gives you the flexibility to do this via a code snippet.
This is especially useful if:
- Your service is only available in specific regions
- You need to comply with export restrictions or local regulations
- You want to reduce fraudulent signups
How It Works
You’ll use the pmpro_registration_checks
filter to check the user’s billing country during registration and prevent signups from certain locations.
Step-by-Step: How to Block Countries in PMPro
Step 1: Access Your Theme’s Functions.php
Go to your WordPress admin panel:
Appearance > Theme File Editor > functions.php
(Or use a custom functionality plugin to avoid theme update overrides.)
Step 2: Add the Country Restriction Code
Here’s a sample code recipe developed by the PMPro team:
function my_pmpro_registration_checks($user_id, $pmpro_level_id, $user_data)
{
// Define the restricted countries and levels
$restricted_countries = [
'level_1' => ['US', 'CA'], // Level 1 restricted to US and Canada
'level_2' => ['AU'], // Level 2 restricted to Australia
];
// Get the user's selected membership level
$membership_level_id = isset($_POST['level']) ? $_POST['level'] : false;
// Check if the selected level is in the restricted array
if ($membership_level_id && isset($restricted_countries['level_' . $membership_level_id])) {
// Get the billing address from the POST data
$billing_country = isset($_POST['billing_country']) ? $_POST['billing_country'] : false;
// Check if the billing country is in the restricted list
if ($billing_country && in_array($billing_country, $restricted_countries['level_' . $membership_level_id])) {
// Return an error message
return 'Sorry, registration is not allowed from your country.';
}
}
return false; // Allow registration if no restrictions apply
}
add_filter('pmpro_registration_checks', 'my_pmpro_registration_checks', 10, 3);
Tip: Country codes should match ISO Alpha-2 codes (e.g., ‘US’ for United States, ‘CA’ for Canada). You can find these in the pmpro_countries array in /includes/countries.php.
Step 3: Test the Restrictions
Once added, try registering with a billing address from a restricted country. The error message “Sorry, registration is not allowed from your country” should appear.
2. Filter Registrations Using OOPSpam Anti-Spam
If your registration forms are being spammed by bots or fake accounts, especially from specific regions, OOPSpam Anti-Spam can help.
This plugin integrates with Paid Memberships Pro and other form systems to provide advanced filtering based on:
- Country
- Language
- IP behavior (VPN, proxy, TOR detection)
- Spam scoring (Machine learning-powered)
- Rate limiting per form
- Submission logging for transparency
How to Set Up OOPSpam with Paid Memberships Pro
Step 1: Install OOPSpam Anti-Spam
From your dashboard, go to:
Plugins > Add New > Search: OOPSpam Anti-Spam
Install and activate the plugin.
Step 2: Get Your API Key
Go to OOPSpam.com, sign up, and generate your API key.
Return to WordPress, and go to:
OOPSpam Anti-Spam > Settings
Paste your API key in the provided field.
Step 3: Enable PMPro Filtering
In the plugin settings, scroll to the Paid Memberships Pro section and activate spam protection for registration forms.
Step 4: Set Country Filtering Rules
Go to the Country Filtering section. You’ll see:
- Allow submissions only from selected countries
- Block submissions from selected countries
Pick your preferred method and select the countries you want to restrict.
Bonus: Review Blocked Entries
OOPSpam gives you submission logs that include:
- IP address
- Country
- Spam score
- Detection reason
- Form field content
- Timestamp
You can view this from:
- Your WordPress dashboard (Form Spam Entries / Form Ham Entries)
- OOPSpam Dashboard (for more details)
This is ideal for monitoring attacks and fine-tuning your filters without losing valuable data.
3. Block Countries Site-Wide Using Cloudflare (Optional)
If you’re under active attack or have compliance requirements, you can block countries at the site level using Cloudflare.
Warning: This blocks visitors from accessing any part of your site, not just the registration form.
Steps to Set Up Country Blocking in Cloudflare
- Log in to Cloudflare
- Select your website
- Navigate to Security > WAF > Firewall Rules
- Click Create Firewall Rule
-
Set the rule to:
- Field:
Country
- Operator:
is in
- Value: Select countries to block
- Action:
Block
- Field:
- Save and deploy the rule
Comparison: Best Way to Block Countries in Paid Memberships Pro
Method | What It Blocks | Best For |
---|---|---|
Custom PHP Code | Membership registration only | Precise control over who can register, level-by-level |
OOPSpam Anti-Spam Plugin | Form submissions only | Spam filtering and country-based form protection |
Cloudflare Firewall | Entire website access | Security threats, scraping bots, or legal/geographical blocks |
Final thoughts
While Paid Memberships Pro doesn’t offer built-in country restrictions, you still have options:
- Use a custom code filter to prevent users from restricted countries from joining specific membership levels.
- Add OOPSpam for an easier, plugin-based approach to stop spam and filter form submissions by country.
- Pair both with Cloudflare firewall rules if you need to block entire countries from accessing your website.
Need help implementing these? Visit the OOPSpam documentation or reach out to support.