Last active
April 12, 2021 22:42
-
-
Save strangerstudios/814cced2249dd2bfa214d4aabfe7795b 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
/* | |
Add a "How did you hear about us?" field Membership Checkout for new members only. | |
Display the field for admins-only in the profile and in the Members List CSV export. | |
*/ | |
function my_pmpro_how_hear_fields() { | |
global $current_user; | |
if(class_exists( 'PMProRH_Field' ) && (!pmpro_hasMembershipLevel() || current_user_can( 'edit_users' ) ) ) { | |
pmprorh_add_checkout_box( 'additional', 'Additional Information' ); | |
$fields = array(); | |
//how_hear field | |
$fields[] = new PMProRH_Field( | |
'how_hear', | |
'select', | |
array( | |
'label' => 'How did you hear about us?', | |
'options' => array( | |
'facebook' => 'Facebook', | |
'twitter' => 'Twitter', | |
'friend' => 'Friend', | |
'other' => 'Other' | |
), | |
'profile' => 'admins', | |
'memberslistcsv' => true, | |
'required' => true, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'how_hear_referrer', | |
'text', | |
array( | |
'label' => 'Referred by', | |
'profile' => 'admins', | |
'memberslistcsv' => true, | |
'depends' => array(array('id' => 'how_hear', 'value' => 'other')) | |
) | |
); | |
foreach($fields as $field) | |
pmprorh_add_registration_field( 'additional', $field ); | |
} | |
} | |
add_action( 'init', 'my_pmpro_how_hear_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Ask “How did you hear about us?” at Membership Checkout" at Paid Memberships Pro here: https://www.paidmembershipspro.com/hear-us-membership-checkout/