Skip to content

Instantly share code, notes, and snippets.

@ideadude
Last active July 13, 2020 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideadude/e00543e7d558ea61769c56d7ba581258 to your computer and use it in GitHub Desktop.
Save ideadude/e00543e7d558ea61769c56d7ba581258 to your computer and use it in GitHub Desktop.
Add a "member_number" field that only admins can edit using PMPro and Register Helper.
<?php
/**
* Add a "member_number" field that only admins can edit.
* Make sure PMPro and the Register Helper Add On are active.
* Copy this code into a Code Snippet or custom plugin.
*/
function my_pmpro_member_number_field() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
// Define the fields.
$fields = array();
$fields[] = new PMProRH_Field(
'member_number', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Member Number', // custom field label
'size' => 40, // input size
'profile' => 'only_admin', // show in user profile
'required' => false, // make this field required
'memberlistcsv' => true,
'addmember' => true
)
);
// Add the fields into a new checkout_boxes are of the checkout page.
foreach ( $fields as $field ) {
pmprorh_add_registration_field(
'checkout_boxes', // location on checkout page
$field // PMProRH_Field object
);
}
// That's it. See the PMPro Register Helper readme for more information and examples.
}
add_action( 'init', 'my_pmpro_member_number_field' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment