Created
January 24, 2022 16:36
-
-
Save kerijacoby/e47b55143b5a5d01dc397397aa22b6a2 to your computer and use it in GitHub Desktop.
PMPro Register Helper Add Radio and Checkbox Fields
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 | |
/* | |
* Add Additional Register Helper fields for: Radio and Checkbox | |
* Save All To User Profile Page | |
* Applies To All Levels | |
*/ | |
// We have to put everything in a function called on init, so we are sure Register Helper is loaded. | |
function pmpro_register_helper_add_radio_checkbox_fields() { | |
// Don't break if Register Helper is not loaded. | |
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) { | |
return false; | |
} | |
// Define the default fields array. | |
$fields = array(); | |
// Add radio options to checkout. | |
$fields[] = new PMProRH_Field( | |
'radio', | |
'radio', | |
array( | |
'label' => 'Radio Options', | |
'profile' => 'true', | |
'required' => 'false', | |
'options' => array( | |
'option1' => 'Option 1', | |
'option2' => 'Option 2', | |
), | |
) | |
); | |
// Add checkbox options to checkout. | |
$fields[] = new PMProRH_Field( | |
'checkboxes', | |
'checkbox_grouped', | |
array( | |
'label' => 'Checkbox Options', | |
'profile' => 'true', | |
'required' => 'false', | |
'options' => array( | |
'option1' => 'Option 1', | |
'option2' => 'Option 2', | |
), | |
) | |
); | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field( | |
'checkout_boxes', | |
$field | |
); | |
} | |
// That's it. See the PMPro Register Helper readme for more information and examples. | |
} | |
add_action( 'init', 'pmpro_register_helper_add_radio_checkbox_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment