Forked from kimcoleman/simple_checkout_name_email_only_signup.php
Last active
August 15, 2022 19:01
-
-
Save kimwhite/99c57bdbbe9ad8188a0ade262f118c57 to your computer and use it in GitHub Desktop.
Only require First Name, Last Name and Email address - works best for Free membership checkouts and when your paid checkout does not require Billing Address.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Only Username and Email address to create user. | |
* Name Fields only on Profile not checkout page | |
* This recipe requires Paid Memberships Pro and the Register Helper Add On. | |
*/ | |
/** | |
* Hide the Account Information Section | |
*/ | |
function simple_checkout_hide_account_information_section( $skip_account_fields, $current_user ) { | |
if ( empty( $current_user->ID ) ) { | |
$skip_account_fields = 1; | |
} | |
return $skip_account_fields; | |
} | |
add_filter( 'pmpro_skip_account_fields', 'simple_checkout_hide_account_information_section', 10, 2 ); | |
/** | |
* Don't load any of the Billing Information fields. | |
*/ | |
function simple_checkout_remove_billing_address_fields( $include ) { | |
return false; | |
} | |
add_filter( 'pmpro_include_billing_address_fields', 'simple_checkout_remove_billing_address_fields' ); | |
/** | |
* Unset required account fields, we'll use Register Helper to require our new fields. | |
*/ | |
function my_required_user_fields( $pmpro_required_user_fields ) { | |
unset( $pmpro_required_user_fields['username'] ); | |
unset( $pmpro_required_user_fields['password'] ); | |
unset( $pmpro_required_user_fields['password2'] ); | |
unset( $pmpro_required_user_fields['bconfirmemail'] ); | |
return $pmpro_required_user_fields; | |
} | |
add_filter( 'pmpro_required_user_fields', 'my_required_user_fields', 10, 2); | |
/** | |
* Register Helper Required Fields | |
*/ | |
function simple_checkout_name_email_only_signup_pmprorh_init() { | |
//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( | |
'username', | |
'text', | |
array( | |
'label' => 'User Name - only half-width alphanumeric characters cannot be spaced', | |
'html_attributes' => array( 'placeholder' => 'only half-width alphanumeric characters cannot be spaced' ), | |
'hint' => 'Hint can go here.', | |
'profile' => false, | |
'required' => true | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'bfirstname', | |
'text', | |
array( | |
'label' => 'First Name', | |
'profile' => "only", | |
'required' => true | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'blastname', | |
'text', | |
array( | |
'label' => 'Last Name', | |
'profile' => "only", | |
'required' => true | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'bemail', | |
'text', | |
array( | |
'label' => 'Email Address', | |
'profile' => true | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'bconfirmemail_copy', | |
'hidden', | |
array( | |
'label' => ' ', | |
'value' => '1', | |
) | |
); | |
pmprorh_add_checkout_box( 'account', 'Account Information'); | |
//add the fields into a new checkout_boxes are of the checkout page | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field( | |
'account', | |
$field | |
); | |
} | |
} | |
add_action( 'init', 'simple_checkout_name_email_only_signup_pmprorh_init' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment