Add below code in top of the file(“class.memberorder.php”).
File path is “paid-memberships-pro\classes\class.memberorder.php”.
Using below code we have add “Organization” field in registration form.
<?php
/*
Adding First and Last Name to Checkout Form
*/
//add the fields to the form
function my_pmpro_checkout_after_password()
{
if(!empty($_REQUEST[‘companyname’]))
$companyname = $_REQUEST[‘companyname’];
else
$companyname = “”;
?>
” />
<?php
}
add_action(‘pmpro_checkout_after_password’, ‘my_pmpro_checkout_after_password’);
//update the user after checkout
function my_update_first_and_last_name_after_checkout($user_id)
{
if(isset($_REQUEST[‘companyname’]))
{
$companyname = $_REQUEST[‘companyname’];
}
elseif(isset($_SESSION[‘companyname’]))
{
//maybe in sessions?
$companyname = $_SESSION[‘companyname’];
//unset
unset($_SESSION[‘companyname’]);
}
if(isset($companyname))
update_user_meta($user_id, “company_name”, $companyname);
}
add_action(‘pmpro_after_checkout’, ‘my_update_first_and_last_name_after_checkout’);
//require the fields
function my_pmpro_registration_checks()
{
global $pmpro_msg, $pmpro_msgt, $current_user;
$companyname = $_REQUEST[‘companyname’];
if($companyname || $current_user->ID)
{
//all good
return true;
}
else
{
$pmpro_msg = “The Organization field are required.”;
$pmpro_msgt = “pmpro_error”;
return false;
}
}
add_filter(“pmpro_registration_checks”, “my_pmpro_registration_checks”);
function my_save_extra_profile_fields( $user_id )
{
if ( !current_user_can( ‘edit_user’, $user_id ) )
return false;
if(isset($_POST[‘companyname’]))
update_usermeta( $user_id, ‘company_name’, $_POST[‘companyname’] );
}
add_action( ‘personal_options_update’, ‘my_save_extra_profile_fields’ );
add_action( ‘edit_user_profile_update’, ‘my_save_extra_profile_fields’ );
/*
These bits are required for PayPal Express only.
*/
function my_pmpro_paypalexpress_session_vars()
{
//save our added fields in session while the user goes off to PayPal
$_SESSION[‘companyname’] = $_REQUEST[‘companyname’];
}
add_action(“pmpro_paypalexpress_session_vars”, “my_pmpro_paypalexpress_session_vars”);