Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created March 8, 2018 10:37
Show Gist options
  • Save kimcoleman/9e618dab9b54c96d34d2c43569d48a07 to your computer and use it in GitHub Desktop.
Save kimcoleman/9e618dab9b54c96d34d2c43569d48a07 to your computer and use it in GitHub Desktop.
Another take on the custom fields for maxk97
<?php
/**
* Custom Fields for various sections of checkout
*/
function my_pmpro_rh_custom_fields() {
global $current_user;
// don't break if Register Helper is not loaded
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
if ( ! pmpro_hasMembershipLevel() || current_user_can( 'edit_users' ) ) {
//pmprorh_add_checkout_box( 'additional', 'Additional Information' );
//How did you hear fields?
$how_hear_fields = array();
// how_hear field
$how_hear_fields[] = new PMProRH_Field(
'how_hear',
'select',
array(
'label' => 'How did you hear about us?',
'options' => array(
'facebook' => 'Facebook',
'twitter' => 'Twitter',
'instagram' => 'Instagram',
'google' => 'Google',
'promotional leaflet' => 'Promotional Leaflet',
'magazine advert' => 'Magazine Advert',
'friend or family' => 'Friend Or Family',
'other' => 'Other',
),
'profile' => 'admins',
'memberslistcsv' => true,
'required' => false,
)
);
$how_hear_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 ( $how_hear_fields as $how_hear_field ) {
pmprorh_add_registration_field( 'checkout_boxes', $how_hear_field );
}
}
// Gender and DOB fields
$gender_dob_fields = array();
$gender_dob_fields[] = new PMProRH_Field( 'gender', 'select', array(
'label' => 'Gender',
'profile' => true,
'required' => false,
'memberslistcsv' => true,
'options' => array(
'' => '',
'male' => 'Male',
'female' => 'Female',
'non-binary' => 'Non-binary',
),
) );
$gender_dob_fields[] = new PMProRH_Field( 'dob', 'date', array(
'label' => 'Date of Birth',
'size' => 40,
'profile' => true,
'required' => false,
'memberslistcsv' => true,
) );
//define the fields
$interests_fields = array();
$interests_fields[] = new PMProRH_Field( ' ', 'html', array( 'html' => '<h2>Select Your Interests</h2>', 'profile' => true, 'required' => false ) );
$interests_fields[] = new PMProRH_Field(
'interests',
'select',
array(
'label' => 'Interests',
'multiple' => true,
'profile' => true,
'required' => false,
'memberslistcsv' => true,
'options' =>
array(
'' => '',
'athletics' => 'Athletics',
'basketball' => 'Basketball',
'boxing' => 'Boxing',
'climbing' => 'Climbing',
'cricket' => 'Cricket',
'cycling' => 'Cycling',
'gym' => 'GYM',
'football' => 'Football',
'golf' => 'Golf',
'hockey' => 'Hockey',
'motocross' => 'Motocross',
'rugby' => 'Rugby',
'running' => 'Running',
'skate' => 'Skate',
'swimming' => 'Swimming',
'tennis' => 'Tennis',
'watersports' => 'Water Sports',
'wintersports' => 'Winter Sports',
),
)
);
// Add the fields in the appropriate spot based on the page.
$checkout_level = $_REQUEST['level'];
if ( ! empty( $checkout_level ) && in_array( $checkout_level, array(3,7,8) ) ) {
// Add Interests Fields
foreach ( $interests_fields as $interests_field ) {
pmprorh_add_registration_field( 'before_submit_button', $interests_field );
}
// Add Gender and Date of Birth Fields
foreach ( $gender_dob_fields as $gender_dob_field ) {
pmprorh_add_registration_field( 'before_submit_button', $gender_dob_field );
}
} elseif ( ! empty( $checkout_level ) && ( $checkout_level === '5' ) ) {
// Add Interests Fields
foreach ( $interests_fields as $interests_field ) {
pmprorh_add_registration_field( 'after_billing_fields', $interests_field );
}
// Add Gender and Date of Birth Fields
foreach ( $gender_dob_fields as $gender_dob_field ) {
pmprorh_add_registration_field( 'after_billing_fields', $gender_dob_field );
}
} else {
// Add Interests Fields
foreach ( $interests_fields as $interests_field ) {
pmprorh_add_registration_field( 'after_email', $interests_field );
}
// Add Gender and Date of Birth Fields
foreach ( $gender_dob_fields as $gender_dob_field ) {
pmprorh_add_registration_field( 'after_email', $gender_dob_field );
}
}
}
add_action( 'init', 'my_pmpro_rh_custom_fields' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment