Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active October 22, 2020 18:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save strangerstudios/7771903 to your computer and use it in GitHub Desktop.
Save strangerstudios/7771903 to your computer and use it in GitHub Desktop.
Add PMPro billing fields to the edit user profile page. You must Paid Memberships Pro and the Register Helper plugin installed. Then add this to a custom plugin or your active theme's functions.php
/*
Add PMPro billing fields to the edit user profile page.
You must Paid Memberships Pro and the Register Helper plugin installed:
http://wordpress.org/extend/plugins/paid-memberships-pro
https://github.com/strangerstudios/pmpro-register-helper
*/
function add_billing_fields_to_profile()
{
global $pmpro_countries;
//check for register helper
if(!function_exists("pmprorh_add_registration_field"))
return;
//define the fields
$fields = array();
$fields[] = new PMProRH_Field("pmpro_baddress1", "text", array("label"=>"Billing Address 1", "size"=>40, "profile"=>true, "required"=>false));
$fields[] = new PMProRH_Field("pmpro_baddress2", "text", array("label"=>"Billing Address 2", "size"=>40, "profile"=>true, "required"=>false));
$fields[] = new PMProRH_Field("pmpro_bcity", "text", array("label"=>"Billing City", "size"=>40, "profile"=>true, "required"=>false));
$fields[] = new PMProRH_Field("pmpro_bstate", "text", array("label"=>"Billing State", "size"=>10, "profile"=>true, "required"=>false));
$fields[] = new PMProRH_Field("pmpro_bzipcode", "text", array("label"=>"Billing Postal Code", "size"=>10, "profile"=>true, "required"=>false));
$fields[] = new PMProRH_Field("pmpro_bcountry", "select", array("label"=>"Billing Country", "profile"=>true, "required"=>false, "options"=>array_merge(array(""=>"- choose one -"), $pmpro_countries)));
$fields[] = new PMProRH_Field("pmpro_bphone", "text", array("label"=>"Billing Phone", "size"=>40, "profile"=>true, "required"=>false));
//add the fields into a new checkout_boxes are of the checkout page
foreach($fields as $field)
pmprorh_add_registration_field("profile", $field);
}
add_action("init", "add_billing_fields_to_profile");
@oneminduniv
Copy link

$fields[] = new PMProRH_Field("pmpro_bcountry", "select", array("label"=>"Billing Country", "profile"=>true, "required"=>false, "options"=>array_merge(array(""=>"- choose one -"), $pmpro_countries)));

This line (select drop down) is showing in the WP profile, but the data is not populating, and the are no options to select.

@yadirina87
Copy link

Because you have to declare the variable as global first:
global $pmpro_countries;

Then it will work .. ;)

@grifini
Copy link

grifini commented Dec 25, 2019

for the billing country field it returns alpha-two codes. Not the full country name!
besides, the revised version did not work. I removed pmpeo_ and it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment