I am trying to calculate the difference and output it like this: "Your membership will be renewed in XXX days."
This is the code I am using ->
add_shortcode( 'membership', 'pren_info');
function pren_info() {
$pren = wp_get_current_user();
$first_name = $pren->first_name;
$last_name = $pren->last_name;
$date_format = 'j M Y H:i';
$today_obj = new DateTime( date( 'Y-m-d', strtotime( 'today' ) ) ); // Get today's Date Object
$register_date = get_the_author_meta( 'user_registered', get_current_user_id() ); // Grab the registration Date
$registered_obj = new DateTime( date( 'Y-m-d', strtotime( $register_date ) ) ); // Get the registration Date Object
$interval_obj = $today_obj->diff( $registered_obj ); // Retrieve the difference Object
$renewal_date = date('Y-m-d',strtotime('+1 year',$register_date));
$datediff = floor(strtotime($renewal_date)/(60*60*24)) - floor(strtotime($register_date)/(60*60*24));
echo '<div class="pren-hello"><b>Hi '.$first_name.'!</b></div>';
if( $interval_obj->days > 1 ) { // The most commonly hit condition at the top
echo __( "Your account was registered {$interval_obj->days} days ago as a member.", "theme" );
} elseif( 0 == $interval_obj->days ) { // IF they registered today
echo __( 'Your account was registered today.', 'theme' );
} elseif( 1 == $interval_obj->days ) { // IF they registered yesterday
echo __( 'Your account was registered yesterday.', 'theme' );
} else { // The off-chance we have less than zero
echo __( 'Please come back tomorrow for an update.', 'theme' );
}
echo '<div class="pren-info">In '.$datediff.' days, your membership needs to be renewed.</div>';
}
The shortcode works in terms of showing the name and showing how many days ago the user got registered, but what I cannot get working is this:
I need to calculate the time of "1 year from the date the user registered and the difference in days between that date and the date they registered".
This is "hard" to explain :) Does it make sense?