Skip to content

Instantly share code, notes, and snippets.

@JarrydLong
Last active May 26, 2021 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JarrydLong/d8fc7f8b7b89d277a03de546438668a8 to your computer and use it in GitHub Desktop.
Save JarrydLong/d8fc7f8b7b89d277a03de546438668a8 to your computer and use it in GitHub Desktop.
<?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