Skip to content

Instantly share code, notes, and snippets.

@MaryOJob
Last active August 5, 2020 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MaryOJob/4188bf758fdc30dbced92fa980ff6057 to your computer and use it in GitHub Desktop.
Save MaryOJob/4188bf758fdc30dbced92fa980ff6057 to your computer and use it in GitHub Desktop.
Adding a Custom Text Field to PMPro Checkout Page
<?php
/**
* Register Helper example for five fields. This is a test Register Helper example.
* Please add the below code to your custom plugin or Code Snippets Plugin by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmprorh_init() {
//don't break if Register Helper is not loaded
if(!function_exists( "pmprorh_add_registration_field" )) {
return false;
}
$fields = array();
$fields[] = new PMProRH_Field(
'sport', // input name, will also be used as meta key
'text', // type of field
array(
'label' => "What Sport Are You Involved In?",
'required' => true, // make this field required
'profile' => true, // show in user profile
'memberslistcsv' => true, //includes in CSV export
));
//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_pmprorh_init","my_pmprorh_depends_fields_init");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment