Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active April 12, 2023 23:22
Show Gist options
  • Save andrewlimaza/563be9bf3a0b369fa3747ec78cad1513 to your computer and use it in GitHub Desktop.
Save andrewlimaza/563be9bf3a0b369fa3747ec78cad1513 to your computer and use it in GitHub Desktop.
Give user default membership level when registering
<?php
// Adjusted from https://www.paidmembershipspro.com/give-users-a-default-membership-level-at-registration/
//Disables the pmpro redirect to levels page when user tries to register
add_filter("pmpro_login_redirect", "__return_false");
function my_pmpro_default_registration_level($user_id) {
$level = pmpro_getLevel( 2 );
$custom_level = array(
'user_id' => $user_id,
'membership_id' => 2,
'code_id' => '',
'initial_payment' => $level->initial_payment,
'billing_amount' => $level->billing_amount,
'cycle_number' => $level->cycle_number,
'cycle_period' => $level->cycle_period,
'billing_limit' => $level->billing_limit,
'trial_amount' => $level->trial_amount,
'trial_limit' => $level->trial_limit,
'startdate' => "'" . current_time('mysql') . "'",
'enddate' => date("Y-m-d", strtotime("+" . $level->expiration_number . " " . $level->expiration_period)),
);
pmpro_changeMembershipLevel($custom_level, $user_id);
}
add_action('user_register', 'my_pmpro_default_registration_level');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment