Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Created November 10, 2020 18:48
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 ronalfy/5c90987bf6d67e21e5a0cc891effe6e0 to your computer and use it in GitHub Desktop.
Save ronalfy/5c90987bf6d67e21e5a0cc891effe6e0 to your computer and use it in GitHub Desktop.
PMPro - Adding Company Name to Register Helper
<?php
/**
* Adds a company name to the checkout page.
*
* 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/
*/
// We have to put everything in a function called on init, so we are sure Register Helper is loaded.
function my_pmprorh_add_company_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(
'company', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Company', // custom field label
'size' => 40, // input size
'class' => 'company', // custom class
'profile' => true, // show in user profile
'required' => true, // make this field required
)
);
// Add the fields into a new checkout_boxes are of the checkout page.
foreach ( $fields as $field ) {
pmprorh_add_registration_field(
'after_email', // location on checkout page
$field // PMProRH_Field object
);
/* /more examples of where to place fields: https://www.paidmembershipspro.com/wp-content/uploads/2013/06/checkout_locations.png */
}
// That's it. See the PMPro Register Helper readme for more information and examples.
}
add_action( 'init', 'my_pmprorh_add_company_field' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment