Bump notes for expiring subscriptions at certain days-remaining thresholds
This commit is contained in:
parent
9f390ba0da
commit
a65ff9e797
|
@ -18,6 +18,16 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes {
|
||||||
const SUBSCRIPTION_NOTE_NAME = 'wc-admin-wc-helper-subscription';
|
const SUBSCRIPTION_NOTE_NAME = 'wc-admin-wc-helper-subscription';
|
||||||
const NOTIFY_WHEN_DAYS_LEFT = 60;
|
const NOTIFY_WHEN_DAYS_LEFT = 60;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We want to bubble up expiration notices when they cross certain age
|
||||||
|
* thresholds. PHP 5.2 doesn't support constant arrays, so we do this.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function get_bump_thresholds() {
|
||||||
|
return array( 60, 45, 20, 7, 1 ); // days.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook all the things.
|
* Hook all the things.
|
||||||
*/
|
*/
|
||||||
|
@ -70,7 +80,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes {
|
||||||
$refresh_notes = false;
|
$refresh_notes = false;
|
||||||
|
|
||||||
// Did the user just do something on the helper page?.
|
// Did the user just do something on the helper page?.
|
||||||
if ( isset( $_GET['wc-helper-status'] ) ) {
|
if ( isset( $_GET['wc-helper-status'] ) ) { // @codingStandardsIgnoreLine.
|
||||||
$refresh_notes = true;
|
$refresh_notes = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,11 +284,26 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes {
|
||||||
if ( $note ) {
|
if ( $note ) {
|
||||||
$content_data = $note->get_content_data();
|
$content_data = $note->get_content_data();
|
||||||
if ( property_exists( $content_data, 'days_until_expiration' ) ) {
|
if ( property_exists( $content_data, 'days_until_expiration' ) ) {
|
||||||
|
// Note: There is no reason this property should not exist. This is just defensive programming.
|
||||||
$note_days_until_expiration = intval( $content_data->days_until_expiration );
|
$note_days_until_expiration = intval( $content_data->days_until_expiration );
|
||||||
if ( $days_until_expiration === $note_days_until_expiration ) {
|
if ( $days_until_expiration === $note_days_until_expiration ) {
|
||||||
// Note is already up to date. Bail.
|
// Note is already up to date. Bail.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we have a note and we are at or have crossed a threshold, we should delete
|
||||||
|
// the old note and create a new one, thereby "bumping" the note to the top of the inbox.
|
||||||
|
$bump_thresholds = $this->get_bump_thresholds();
|
||||||
|
$crossing_threshold = false;
|
||||||
|
|
||||||
|
foreach ( (array) $bump_thresholds as $bump_threshold ) {
|
||||||
|
if ( ( $note_days_until_expiration > $bump_threshold ) && ( $days_until_expiration <= $bump_threshold ) ) {
|
||||||
|
error_log( "note crossed the $bump_threshold days until expiration threshold" );
|
||||||
|
$note->delete();
|
||||||
|
unset( $note );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,10 +435,12 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the subscription is not expiring soon, clean up and exit.
|
// If the subscription is not expiring by the first threshold, clean up and exit.
|
||||||
|
$bump_thresholds = $this->get_bump_thresholds();
|
||||||
|
$first_threshold = DAY_IN_SECONDS * $bump_thresholds[0];
|
||||||
$expires = intval( $subscription['expires'] );
|
$expires = intval( $subscription['expires'] );
|
||||||
$time_now_gmt = current_time( 'timestamp', 0 );
|
$time_now_gmt = current_time( 'timestamp', 0 );
|
||||||
if ( $expires > $time_now_gmt + self::NOTIFY_WHEN_DAYS_LEFT * DAY_IN_SECONDS ) {
|
if ( $expires > $time_now_gmt + $first_threshold ) {
|
||||||
$this->delete_any_note_for_product_id( $product_id );
|
$this->delete_any_note_for_product_id( $product_id );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue