NOTICE: This post is outdated and it is possible not to work as expected.

NOTE: If you are using a different field for gender, change "I am a" with the name of your gender field

To assign a free membership to female users once they register, add the following code to your functions.php at child theme

COPY CODE
/**
* When registering, add the member to a specific membership level
* based on the field value he has selected
*
* @global object $wpdb
* @global object $bp
* @param integer $user_id
*/
function kleo_pmpro_default_level($user_id) {
    global $wpdb, $bp;
 
    //Change this with your field name
    $field_name= "I am a";
 
    //Change the field value
    $value_to_match = "Woman";
 
    //Membership level id
    $membership_level = 1;
 
    //Done editing
    $field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) );
    if ($_POST['field_'.$field_id] == $value_to_match) {
            pmpro_changeMembershipLevel($membership_level, $user_id);
    }
}
 
function kleo_mu_pmpro_default_level($user_id, $password, $meta) {
    global $bp, $wpdb;
 
    //Change this with your field name
    $field_name= "I am a";
 
    //Change the field value
    $value_to_match = "Woman";
 
    //Membership level id
    $membership_level = 1;
 
    
    //Done editing
    $field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) );
    $field_value = $meta['field_'.$field_id];
    if ( $field_value == $value_to_match ) {
        pmpro_changeMembershipLevel($membership_level, $user_id);
    }
}
 
if (is_multisite()) {
    add_action( 'wpmu_activate_user', 'kleo_mu_pmpro_default_level', 10, 3);
} else {
    add_action('user_register', 'kleo_pmpro_default_level');
}

To assign a free membership to male users once they register, add the following code to your functions.php at child theme

COPY CODE
/**
* When registering, add the member to a specific membership level
* based on the field value he has selected
*
* @global object $wpdb
* @global object $bp
* @param integer $user_id
*/
function kleo_pmpro_default_level($user_id) {
    global $wpdb, $bp;
 
    //Change this with your field name
    $field_name= "I am a";
 
    //Change the field value
    $value_to_match = "Woman";
 
    //Membership level id
    $membership_level = 1;
 
    //Done editing
    $field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) );
    if ($_POST['field_'.$field_id] == $value_to_match) {
            pmpro_changeMembershipLevel($membership_level, $user_id);
    }
}
 
function kleo_mu_pmpro_default_level($user_id, $password, $meta) {
    global $bp, $wpdb;
 
    //Change this with your field name
    $field_name= "I am a";
 
    //Change the field value
    $value_to_match = "Man";
 
    //Membership level id
    $membership_level = 1;
 
    
    //Done editing
    $field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) );
    $field_value = $meta['field_'.$field_id];
    if ( $field_value == $value_to_match ) {
        pmpro_changeMembershipLevel($membership_level, $user_id);
    }
}
 
if (is_multisite()) {
    add_action( 'wpmu_activate_user', 'kleo_mu_pmpro_default_level', 10, 3);
} else {
    add_action('user_register', 'kleo_pmpro_default_level');
}

Log in with your credentials

Forgot your details?