Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Created September 8, 2018 13:54
Show Gist options
  • Save pbrocks/6ee58ec0e3a60f882fa94de591347778 to your computer and use it in GitHub Desktop.
Save pbrocks/6ee58ec0e3a60f882fa94de591347778 to your computer and use it in GitHub Desktop.
Add a PMPro Register Helper conditional field to your checkout and profile screens.
<?php // Do not include in PMPro Customizations plugin
/**
* Add a conditional Register Helper field with a checkbox that needs to be checked in order to show a Date field.
*/
function initialize_conditional_dob() {
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
// define the fields
$fields = array();
/**
* Conditional field example. Date field showing depends on checkbox value
*/
$fields[] = new PMProRH_Field(
'checking_condition',
'checkbox',
array(
'label' => 'Enter DOB',
'text' => 'Enter your date of birth',
'profile' => true,
)
);
$fields[] = new PMProRH_Field(
'date_of_birth_2',
'date',
array(
'depends' => array(
array(
'id' => 'checking_condition',
'value' => true,
),
),
'required' => true,
'label' => 'Date Of Birth',
'size' => 40,
'profile' => true,
)
);
foreach ( $fields as $field ) {
pmprorh_add_registration_field(
'checkout_boxes',
$field
);
}
}
add_action( 'init', 'initialize_conditional_dob' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment