Last active
January 20, 2022 19:05
-
-
Save femiyb/d3cb51d11ffabef2c97b84987d4856f0 to your computer and use it in GitHub Desktop.
Add State and Country to Account Information
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 does Add State and Country to Account Information. | |
* | |
* 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/ | |
*/ | |
/* | |
* Register Helper fields. | |
* | |
*/ | |
// We have to put everything in a function called on init, so we are sure Register Helper is loaded. | |
function my_pmprorh_init_add_fields() | |
{ | |
//don’t break if Register Helper is not loaded | |
if(!function_exists("pmprorh_add_registration_field")) | |
{ | |
return false; | |
} | |
global $pmpro_countries, $pmpro_states; | |
$countries = array_merge( array( '' => 'Choose One' ), $pmpro_countries ); | |
$states = array_merge( array( '' => 'Choose One' ), $pmpro_states ); | |
//define the fields | |
$fields = array(); | |
$fields[] = new PMProRH_Field( | |
'bcountry', | |
'select', | |
array( | |
'label' => 'Country', | |
'required' => true, // make field required, set value to false to make it optional | |
'profile' => true, // show in user profile | |
'options' => $countries, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'bstate', | |
'select', | |
array( | |
'label' => 'State', | |
'required' => true, // make field required, set value to false to make it optional | |
'profile' => true, // show in user profile | |
'options' => $states, | |
) | |
); | |
foreach($fields as $field) | |
pmprorh_add_registration_field( | |
'after_email', // location on checkout page | |
$field // PMProRH_Field object | |
); | |
//that’s it. see the PMPro Register Helper readme for more information and examples. | |
} | |
add_action("init", "my_pmprorh_init_add_fields"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment