Created
July 5, 2021 06:03
-
-
Save ipokkel/0696348f59f707d12a123cf05aca63cc to your computer and use it in GitHub Desktop.
Example checkbox grouped field for PMPro Regiser Helper.
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 | |
/** | |
* This recipe creates custom fields for membership registration. | |
* | |
* @requires Register Helper Add On | |
* @link https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/ | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmprorh_init_custom_registration_fields_1625464156() { | |
// don't break if Register Helper is not loaded | |
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) { | |
return false; | |
} | |
// define the fields | |
$fields = array(); | |
// GROUPED CHECKBOX | |
$fields[] = new PMProRH_Field( | |
'checkbox_grouped_example', // input field name, used as meta key | |
'checkbox_grouped', // field type | |
array( | |
'label' => 'Checkbox Grouped', | |
'hint' => 'This is a hint', // display a hint under field | |
'options' => array( // <option> elements for select field | |
'option_1' => 'Option 1', // <option value=”option_1”>Option 1</option> | |
'option_2' => 'Option 2', // <option value=”option_2”>Option 2</option> | |
'option_3' => 'Option 3', // <option value=”option_3”>Option 3</option> | |
'option_4' => 'Option 4', // <option value=”option_4”>Option 4</option> | |
), | |
'profile' => true, // show on profile | |
'memberslistcsv' => true, // include when using export members to csv | |
'addmember' => true, // include when using add member from admin | |
// 'required' => true, // make field required | |
) | |
); | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field( | |
'checkout_boxes', // location on checkout page | |
$field // PMProRH_Field object | |
); | |
} | |
unset( $field ); | |
// that's it. see the PMPro Register Helper readme for more information and examples. | |
} | |
add_action( 'init', 'my_pmprorh_init_custom_registration_fields_1625464156' ); |
@p-prado You should consider moving the asterisk to inside the field label - https://gist.github.com/ipokkel/9cb626b95e37d1a45faba69ac8fe21fa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ipokkel @strangerstudios, I'm having trouble showing the asterisk next to the label for the checkbox_grouped. I was able to show it for all other fields, but not this one. Is there any special settings I need to change?
I already have:
Still, the asterisk is not showing.
Any help is greatly appreciated!