Skip to content

Instantly share code, notes, and snippets.

@kerijacoby
Created January 24, 2022 16:36
Show Gist options
  • Save kerijacoby/e47b55143b5a5d01dc397397aa22b6a2 to your computer and use it in GitHub Desktop.
Save kerijacoby/e47b55143b5a5d01dc397397aa22b6a2 to your computer and use it in GitHub Desktop.
PMPro Register Helper Add Radio and Checkbox Fields
<?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