Automattic\WooCommerce\Internal\StockNotifications

DataRetentionController::do_wc_customer_stock_notifications_daily │ public │ WC 1.0

Deletes overdue notifications based on the configured time threshold. It retrieves notifications that are pending and past the threshold, then deletes them, except those whose verification email was resent within the threshold.

Method of the class: DataRetentionController{}

No Hooks.

Returns

void. Nothing (null).

Usage

$DataRetentionController = new DataRetentionController();
$DataRetentionController->do_wc_customer_stock_notifications_daily();

DataRetentionController::do_wc_customer_stock_notifications_daily() code WC 11.3.0

public function do_wc_customer_stock_notifications_daily() {
	$time_threshold = Config::get_unverified_deletion_days_threshold();

	if ( 0 === $time_threshold ) {
		return;
	}
	$overdue_threshold = time() - $time_threshold * DAY_IN_SECONDS;

	$overdue_notifications = NotificationQuery::get_notifications(
		array(
			'status'   => NotificationStatus::PENDING,
			'end_date' => gmdate( 'Y-m-d H:i:s', $overdue_threshold ),
		)
	);

	foreach ( $overdue_notifications as $notification_id ) {
		$notification = Factory::get_notification( $notification_id );
		if ( ! $notification instanceof Notification ) {
			continue;
		}

		// Keep sign-ups whose verification email was resent within the retention window.
		$last_verify_email_sent_at = (int) $notification->get_meta( NotificationManagementService::LAST_VERIFY_EMAIL_SENT_META );
		if ( $last_verify_email_sent_at <= $overdue_threshold ) {
			$notification->delete();
		}
	}
}