Skip to content

Instantly share code, notes, and snippets.

@travislima
Last active March 16, 2022 13:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travislima/391c0db4121366a40eaa1bb5f8d18978 to your computer and use it in GitHub Desktop.
Save travislima/391c0db4121366a40eaa1bb5f8d18978 to your computer and use it in GitHub Desktop.
Step 3 - Register Helper: A step-by-step guide on creating custom fields.
<?php //Do not copy this tag.
/**
* Add custom fields to Paid Memberships Pro checkout page.
* Must have PMPro & Register Helper Add On installed and activated to work.
* Add this code to a PMPro Customizations Plugin or Code Snippets plugin.
*/
function pmpro_add_fields_to_checkout(){
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
}
$fields = array();
$fields[] = new PMProRH_Field(
'company', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Company', // custom field label
'profile' => true, // show in user profile
'required' => true, // make this field required
)
);
$fields[] = new PMProRH_Field(
'pet', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Name of Pet', // custom field label
)
);
$fields[] = new PMProRH_Field(
'telephone', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Telephone', // custom field label
'required' => true, // make this field required
'profile' => true, // show in user profile
)
);
//add the fields to default forms
foreach($fields as $field){
pmprorh_add_registration_field(
'checkout_boxes', // location on checkout page
$field // PMProRH_Field object
);
}
}
add_action( 'init', 'pmpro_add_fields_to_checkout' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment