adde event expire card reminder

This commit is contained in:
asus
2024-04-09 23:05:11 +02:00
parent 1f03fa1a7b
commit 1775c86c25
4 changed files with 41 additions and 23 deletions

View File

@@ -89,11 +89,11 @@ function schedule_prof_account_deletion_CIPF($user_id) {
if (false === $date_limit) {
return;
}
$date_limit->modify($duration_deletion);
$delay = $date_limit->getTimestamp();
wp_schedule_single_event($delay, 'CIPF_schedule_event_prof_account_deletion', array($user_id));
$new_date = $date_limit->modify($duration_deletion);
$delay = $new_date->getTimestamp();
wp_schedule_single_event($delay, 'CIPF_prof_account_deletion', array($user_id));
}
add_action('CIPF_schedule_event_prof_account_deletion', 'handle_prof_account_deletion_CIPF');
add_action('CIPF_prof_account_deletion', 'handle_prof_account_deletion_CIPF');
@@ -104,17 +104,16 @@ add_action('CIPF_schedule_event_prof_account_deletion', 'handle_prof_account_del
*/
function schedule_deactivate_expired_card_CIPF($user_id) {
Plgntls::debug_infos();
$duration_validity = Cipf::DURATION_CARD_VALIDITY;
$date_limit = get_card_date_expiration_CIPF($user_id);
if (false === $date_limit) {
return;
}
$date_limit->modify('+1 day');
$delay = $date_limit->getTimestamp();
wp_schedule_single_event($delay, 'CIPF_schedule_event_deactivate_expired_card', array($user_id));
$new_date = $date_limit->modify('+1 day');
$delay = $new_date->getTimestamp();
wp_schedule_single_event($delay, 'CIPF_deactivate_expired_card', array($user_id));
}
add_action('CIPF_schedule_event_deactivate_expired_card', 'handle_card_expire_CIPF');
add_action('CIPF_deactivate_expired_card', 'handle_card_expire_CIPF');
@@ -122,16 +121,24 @@ add_action('CIPF_schedule_event_deactivate_expired_card', 'handle_card_expire_CI
/*
* 4. && 5. prof, send email reminder before account expire
*
function schedule__CIPF($user_id) {
Plgntls::debug_infos();
$delay = strtotime('+3 days');
wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id));
}
function event_CIPF($user_id) {
Plgntls::debug_infos();
}
add_action('schedule_event_CIPF', 'event_CIPF', 10, 2);
*/
function schedule_reminder_before_card_expire_CIPF($user_id) {
Plgntls::debug_infos();
$card_reminder_1 = Cipf::DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_FIRST;
$card_reminder_2 = Cipf::DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_LAST;
$date_limit = get_card_date_expiration_CIPF($user_id);
if (false === $date_limit) {
return;
}
$new_date_1 = $date_limit->modify($card_reminder_1);
$new_date_2 = $date_limit->modify($card_reminder_2);
$delay_1 = $new_date_1->getTimestamp();
$delay_2 = $new_date_2->getTimestamp();
wp_schedule_single_event($delay_1, 'CIPF_reminder_before_card_expire', array('card_will_expire', $user_id));
wp_schedule_single_event($delay_2, 'CIPF_reminder_before_card_expire', array('card_will_expire', $user_id));
}
add_action('CIPF_reminder_before_card_expire', 'send_emails_CIPF', 10, 2);

View File

@@ -42,7 +42,7 @@ function get_date_CIPF($acf_date, $user_id) {
// compare 2 dates : https://stackoverflow.com/q/8722806/9497573
// also I dont use strtotime to compare 2 ints,
// because i don't know if it will fail one day (2000y bug style)
$current_date = date_create_from_format($current_format_field, $current_date_string);
$current_date = date_create_immutable_from_format($current_format_field, $current_date_string);
if ($current_date === false) {
return false;
}
@@ -96,10 +96,10 @@ function get_new_date_CIPF($date, $duration) {
$current_date = $date;
// empty return true for false, null, empty string and array, and 0
if (empty($date)) {
$current_date = date_create('today');
$current_date = date_create_immutable('today');
}
else if (!$current_date instanceof DateTimeInterface) {
$current_date = date_create('today');
$current_date = date_create_immutable('today');
}
/*

View File

@@ -176,6 +176,7 @@ function success_payment_for_user_CIPF($user_id, $order_id) {
update_card_date_expiration_CIPF($user_id);
schedule_deactivate_expired_card_CIPF($user_id);
schedule_prof_account_deletion_CIPF($user_id);
schedule_reminder_before_card_expire_CIPF($user_id);
if (is_card_new_CIPF($user_id)) {
set_card_number_CIPF($user_id);