Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eighty20results/f707600d38325fd1ca02 to your computer and use it in GitHub Desktop.
Save eighty20results/f707600d38325fd1ca02 to your computer and use it in GitHub Desktop.
Preserve startdate on membership level change
/*
Keep members start dates at checkout, even if switching levels.
*/
function custom_pmpro_checkout_start_date($date, $user_id, $level)
{
global $wpdb;
// Comment this out if you want to use the users registration date (Warning: Registration date may not contain data...)
$sqlQuery = "SELECT UNIX_TIMESTAMP(startdate) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . esc_sql($user_id) . "' ORDER BY id LIMIT 1";
// Uncomment to use the user registration date rather than the "initial membership purchased" date (even if it's a "free" membership)
// $sqlQuery = "SELECT UNIX_TIMESTAMP(user_registered) FROM $wpdb->users WHERE user_id = '" . esc_sql($user_id) . "' ORDER BY id LIMIT 1";
$old_timestamp = $wpdb->get_var($sqlQuery);
if(!empty($old_timestamp))
$date = date("Y-m-d H:i:s", $old_timestamp);
return $date;
}
add_action('pmpro_checkout_start_date','custom_pmpro_checkout_start_date', 15, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment