Last active
May 26, 2021 06:09
-
-
Save JarrydLong/d8fc7f8b7b89d277a03de546438668a8 to your computer and use it in GitHub Desktop.
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 will update all member's billing country to Germany. | |
* | |
* Exercise caution when making these changes. They cannot be undone. Make a backup of your database | |
* before running this script. | |
* | |
* Enter /wp-admin/?updateusercountry=true in your URL to run the script. | |
* | |
* | |
* 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 mypmpro_update_users_country(){ | |
//run /wp-admin/?updateusercountry=true | |
if( isset( $_REQUEST['updateusercountry'] ) ){ | |
$users = get_users( ); | |
if( $users ){ | |
foreach( $users as $user ){ | |
$meta = get_user_meta( $user->ID, 'pmpro_bcountry', true ); | |
if( $meta !== "" && $meta !== "DE" ){ | |
//Not empty and not in Germany, update | |
update_user_meta( $user->ID, 'pmpro_bcountry', 'DE' ); | |
} | |
} | |
} | |
} | |
} | |
add_action( 'admin_init', 'mypmpro_update_users_country' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment