Show expiring and expired notices to active and unconnected subscriptions (#50383)
This commit is contained in:
parent
de05966754
commit
1806747254
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: update
|
||||
|
||||
Show expiring and expired notices to active and unconnected subscriptions
|
|
@ -259,8 +259,13 @@ class WC_Helper_Updater {
|
|||
// Extract product ID from the response.
|
||||
$product_id = preg_replace( '/[^0-9]/', '', $response->id );
|
||||
|
||||
$installed_or_unconnected = array_merge(
|
||||
WC_Helper::get_installed_subscriptions(),
|
||||
WC_Helper::get_unconnected_subscriptions()
|
||||
);
|
||||
|
||||
// Product subscriptions.
|
||||
$subscriptions = wp_list_filter( WC_Helper::get_installed_subscriptions(), array( 'product_id' => $product_id ) );
|
||||
$subscriptions = wp_list_filter( $installed_or_unconnected, array( 'product_id' => $product_id ) );
|
||||
if ( empty( $subscriptions ) ) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1334,6 +1334,34 @@ class WC_Helper {
|
|||
return $installed_subscriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's unconnected subscriptions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_unconnected_subscriptions() {
|
||||
static $unconnected_subscriptions = null;
|
||||
|
||||
// Cache unconnected_subscriptions in the current request.
|
||||
if ( is_null( $unconnected_subscriptions ) ) {
|
||||
$auth = WC_Helper_Options::get( 'auth' );
|
||||
$site_id = isset( $auth['site_id'] ) ? absint( $auth['site_id'] ) : 0;
|
||||
if ( 0 === $site_id ) {
|
||||
$unconnected_subscriptions = array();
|
||||
return $unconnected_subscriptions;
|
||||
}
|
||||
|
||||
$unconnected_subscriptions = array_filter(
|
||||
self::get_subscriptions(),
|
||||
function ( $subscription ) use ( $site_id ) {
|
||||
return empty( $subscription['connections'] );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return $unconnected_subscriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subscription state of a given product ID.
|
||||
*
|
||||
|
|
|
@ -839,7 +839,7 @@ class PluginsHelper {
|
|||
$subscriptions,
|
||||
function ( $sub ) {
|
||||
return ( ! empty( $sub['local']['installed'] ) && ! empty( $sub['product_key'] ) )
|
||||
&& $sub['active']
|
||||
&& ( $sub['active'] || empty( $sub['connections'] ) ) // Active on current site or not connected to any sites.
|
||||
&& $sub['expiring']
|
||||
&& ! $sub['autorenew'];
|
||||
},
|
||||
|
@ -917,7 +917,7 @@ class PluginsHelper {
|
|||
$subscriptions,
|
||||
function ( $sub ) {
|
||||
return ( ! empty( $sub['local']['installed'] ) && ! empty( $sub['product_key'] ) )
|
||||
&& $sub['active']
|
||||
&& ( $sub['active'] || empty( $sub['connections'] ) ) // Active on current site or not connected to any sites.
|
||||
&& $sub['expired']
|
||||
&& ! $sub['lifetime'];
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue