Automattic\WooCommerce\Internal\Admin\Notes
WooSubscriptionsNotes::refresh_subscription_notes
For each active subscription on this site, checks the expiration date and creates/updates/deletes notes.
Метод класса: WooSubscriptionsNotes{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$WooSubscriptionsNotes = new WooSubscriptionsNotes(); $WooSubscriptionsNotes->refresh_subscription_notes();
Код WooSubscriptionsNotes::refresh_subscription_notes() WooSubscriptionsNotes::refresh subscription notes WC 10.3.4
public function refresh_subscription_notes() {
if ( ! $this->is_connected() ) {
return;
}
$this->prune_inactive_subscription_notes();
try {
$subscriptions = \WC_Helper::get_subscriptions();
} catch ( \Exception $e ) {
$subscriptions = array();
}
$active_product_ids = $this->get_subscription_active_product_ids();
foreach ( (array) $subscriptions as $subscription ) {
// Only concern ourselves with active products.
$product_id = $subscription['product_id'];
if ( ! in_array( $product_id, $active_product_ids, true ) ) {
continue;
}
// If the subscription will auto-renew, clean up and exit.
if ( $subscription['autorenew'] ) {
$this->delete_any_note_for_product_id( $product_id );
continue;
}
// If the subscription is not expiring by the first threshold, clean up and exit.
$first_threshold = DAY_IN_SECONDS * self::BUMP_THRESHOLDS[0];
$expires = intval( $subscription['expires'] );
$time_now_gmt = current_time( 'timestamp', 0 );
if ( $expires > $time_now_gmt + $first_threshold ) {
$this->delete_any_note_for_product_id( $product_id );
continue;
}
// Otherwise, if the subscription can still have auto-renew enabled, let them know that now.
if ( $expires > $time_now_gmt ) {
$this->add_or_update_subscription_expiring( $subscription );
continue;
}
// If we got this far, the subscription has completely expired, let them know.
$this->add_or_update_subscription_expired( $subscription );
}
}