Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active July 28, 2021 16:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/2e569b6fff69446f638abd908930d7aa to your computer and use it in GitHub Desktop.
Save ipokkel/2e569b6fff69446f638abd908930d7aa to your computer and use it in GitHub Desktop.
Remove all countries except the default PMPro country.
<?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