Use this function:
There is a field price_ which contains the ID of the price set selected
Iterate through price sets to find this ID, and if membership matches, use this number of terms
Be sure to set membership type ID as $membership_type_id
$membership_num_terms = 1;
if (isset($form->_values['fee'])) {
foreach ($form->_values['fee'] as $index => $values) {
if (isset($form->_params['price_' . $index])) {
$id = intval($form->_params['price_' . $index]);
} else {
$id = null;
}
foreach ($values['options'] as $option_index => $option_values) {
if (($option_index == $id) && ($option_values['membership_type_id'] == $membership_type_id)) {
$membership_num_terms = $option_values['membership_num_terms'];
}
}
}
}