Last active
February 28, 2025 12:39
-
-
Save ipokkel/2e569b6fff69446f638abd908930d7aa to your computer and use it in GitHub Desktop.
Remove all countries except the default PMPro country.
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 | |
/** | |
* This recipe is an example of how to keep only the PMPro default country | |
* and remove all other countries from the "Country" dropdown select. | |
* | |
* The PMPro default country is "US" (United States), to set | |
* your custom default country, please refer to this article. | |
* @link https://www.paidmembershipspro.com/change-the-default-country-of-your-membership-website/ | |
* | |
* For available countries and their shortcode see: | |
* @link https://github.com/strangerstudios/paid-memberships-pro/blob/master/includes/countries.php | |
* | |
* NOTE: This recipe is not intended for or compatible with the PMPro State Dropdowns Add On. | |
* | |
* 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_countries_show_only_default_country( $countries ) { | |
global $pmpro_default_country; | |
foreach ( $countries as $country_code => $country_name ) { | |
if ( $pmpro_default_country !== $country_code ) { | |
// remove other countries | |
unset( $countries[ $country_code ] ); | |
} | |
} | |
unset( $country_code ); | |
return $countries; | |
} | |
add_filter( 'pmpro_countries', 'my_pmpro_countries_show_only_default_country' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment