Skip to content

Instantly share code, notes, and snippets.

@kimwhite
Last active September 15, 2023 16:39
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 kimwhite/8e262655087538a0b3b1c0c4507289e8 to your computer and use it in GitHub Desktop.
Save kimwhite/8e262655087538a0b3b1c0c4507289e8 to your computer and use it in GitHub Desktop.
<?php
/*
* Plugin Name: This snippet will remove username, email confirmation, and all builling. Adding a few of the users own fields.
* 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/
*/
//Now start placing your customization code below this line
/**
* 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_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(
'bemail',
'text',
array(
'label' => 'Email Address',
'profile' => true
)
);
$fields[] = new PMProRH_Field(
'bconfirmemail_copy',
'hidden',
array(
'label' => '&nbsp;',
'value' => '1',
)
);
$fields[] = new PMProRH_Field(
'pmpro_bcity',
'text',
array(
'label'=>'City',
'size'=>40,
'profile'=>true,
'required'=>true,
'addmember' => true
)
);
global $pmpro_countries;
$countries = array_merge(array("" => "Choose One"), $pmpro_countries);
$fields[] = new PMProRH_Field(
"bcountry",
"select",
array(
"label"=>"Country",
"required" => true,
"profile" => true, // show in user profile
"options"=> $countries
)
);
$fields[] = new PMProRH_Field(
'pmpro_youfieldname',
'text',
array(
'label'=>'Your Fiedl Name',
'size'=>40,
'profile'=>true,
'required'=>false,
'addmember' => true
)
);
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_email_only_signup_pmprorh_init' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment