Your membership site may only accept members from specific countries. Paid Memberships Pro includes a country field at checkout and in other areas of the member experience. This recipe replaces the default country list with your own custom list, so only the countries you specify are available at checkout and in other country dropdowns.

Featured image for code recipe on customizing the country dropdown at checkout

Understanding the pmpro_countries Filter

This recipe uses the pmpro_countries filter. This filter allows you to change the list of countries wherever Paid Memberships Pro displays a country dropdown — at checkout, on the Member Profile Edit page, and on the admin user profile screen.

In this example, we replace the default country list with a shorter, custom list. This is useful for restricting membership to specific countries and making checkout simpler for members.

Animated gif showing the customized country dropdown

About the Code Recipe

This code recipe creates a custom list of countries and sorts them alphabetically. You can add or remove countries in any order. To build your list, reference the full list of country codes. You will use the codes to edit the code recipe.

The Code Recipe

How to Edit the List of Countries

In the code recipe, look at the array in lines 28-30:

'US' => 'United States',
'CA' => 'Canada',
'GB' => 'United Kingdom',

Each line represents a country:

  • Two letters before the arrow (=>) are the country code.
  • Text in quotes after the arrow is what members see in the dropdown.

To remove a country: Delete the entire line for that country.
To add a country: Add a new line using its code and name.

You don’t need to worry about the order — the recipe automatically sorts the list alphabetically.

Adding the Recipe to Your Website

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.

Video: Coding with Sam Walkthrough

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics


Was this article helpful?
YesNo