Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created October 29, 2018 08:29
Show Gist options
  • Save andrewlimaza/e1421a2b41f161fbe091c72674c3be73 to your computer and use it in GitHub Desktop.
Save andrewlimaza/e1421a2b41f161fbe091c72674c3be73 to your computer and use it in GitHub Desktop.
Register Helper Example For Paid Memberships Pro.
<?php
/**
* Copy this code (below) into your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
}
$states = array(
'' => 'Please Select',
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DE' => 'Delaware',
'DC' => 'District Of Columbia',
'FL' => 'Florida',
'GA' => 'Georgia',
'HI' => 'Hawaii',
'ID' => 'Idaho',
'IL' => 'Illinois',
'IN' => 'Indiana',
'IA' => 'Iowa',
'KS' => 'Kansas',
'KY' => 'Kentucky',
'LA' => 'Louisiana',
'ME' => 'Maine',
'MD' => 'Maryland',
'MA' => 'Massachusetts',
'MI' => 'Michigan',
'MN' => 'Minnesota',
'MS' => 'Mississippi',
'MO' => 'Missouri',
'MT' => 'Montana',
'NE' => 'Nebraska',
'NV' => 'Nevada',
'NH' => 'New Hampshire',
'NJ' => 'New Jersey',
'NM' => 'New Mexico',
'NY' => 'New York',
'NC' => 'North Carolina',
'ND' => 'North Dakota',
'OH' => 'Ohio',
'OK' => 'Oklahoma',
'OR' => 'Oregon',
'PA' => 'Pennsylvania',
'RI' => 'Rhode Island',
'SC' => 'South Carolina',
'SD' => 'South Dakota',
'TN' => 'Tennessee',
'TX' => 'Texas',
'UT' => 'Utah',
'VT' => 'Vermont',
'VA' => 'Virginia',
'WA' => 'Washington',
'WV' => 'West Virginia',
'WI' => 'Wisconsin',
'WY' => 'Wyoming',
);
//define the fields
$fields = array();
$fields[] = new PMProRH_Field(
'date_of_birth', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Date of Birth', // custom field label
'size' => 40, // input size
'profile' => true, // show in user profile
'required' => true, // make this field required
)
);
$fields[] = new PMProRH_Field(
'profile_picture', // input name, will also be used as meta key
'file', // type of field
array(
'label' => 'Profile Picture', // custom field label
'profile' => true, // only show in profile for admins
'required' => true,
)
);
$fields[] = new PMProRH_Field(
'facebook', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Facebook Link', // custom field label
'size' => 40, // input size
'profile' => true, // show in user profile
'required' => true, // make this field required
)
);
$fields[] = new PMProRH_Field(
'city', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'City', // custom field label
'size' => 40, // input size
'profile' => true, // show in user profile
'required' => true, // make this field required
)
);
$fields[] = new PMProRH_Field(
'state', // input name, will also be used as meta key
'select', // type of field
array(
'label' => 'State',
'options' => $states
)
);
//add the fields into a new checkout_boxes are of the checkout page
foreach($fields as $field)
pmprorh_add_registration_field(
'checkout_boxes', // 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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment