ty( $sub['product_key'] ) )
&& ( $sub['active'] || empty( $sub['connections'] ) ) // Active on current site or not connected to any sites.
&& $sub['expired']
&& ! $sub['lifetime'];
},
);
if ( ! $expired_subscriptions ) {
return array();
}
$total_expired_subscriptions = count( $expired_subscriptions );
self::$subscription_usage_notices_already_shown = true;
$notice_data = self::get_subscriptions_notice_data(
$subscriptions,
$expired_subscriptions,
$total_expired_subscriptions,
array(
/* translators: 1) product name 3) URL to My Subscriptions page 4) Renew product price string */
'single_manage' => __( 'Your subscription for %1$s expired. %4$s to continue receiving updates and streamlined support.', 'woocommerce' ),
/* translators: 1) product name 3) URL to My Subscriptions page 4) Renew product price string */
'multiple_manage' => __( 'One of your subscriptions for %1$s has expired. %4$s to continue receiving updates and streamlined support.', 'woocommerce' ),
/* translators: 1) total expired subscriptions 2) URL to My Subscriptions page */
'different_subscriptions' => __( 'You have %1$s Woo extension subscriptions that expired. Renew to continue receiving updates and streamlined support.', 'woocommerce' ),
),
'expired',
);
$button_link = add_query_arg(
array(
'add-to-cart' => $notice_data['product_ids'],
'utm_source' => 'pu',
'utm_campaign' => $allowed_link ? 'pu_settings_screen_renew' : 'pu_in_apps_screen_renew',
),
self::WOO_CART_PAGE_URL
);
if ( in_array( $notice_data['type'], array( 'single_manage', 'multiple_manage' ), true ) ) {
$button_link = add_query_arg(
array(
'add-to-cart' => $notice_data['product_id'],
),
$button_link
);
}
return array(
'description' => $allowed_link ? $notice_data['parsed_message'] : preg_replace( '#(.*?)#i', '\1', $notice_data['parsed_message'] ),
'button_text' => __( 'Renew', 'woocommerce' ),
'button_link' => $button_link,
);
}
/**
* Get formatted notice information for missing subscription.
*
* @return array notice information.
*/
public static function get_missing_subscription_notice() {
if ( ! WC_Helper::is_site_connected() ) {
return array();
}
if ( self::$subscription_usage_notices_already_shown ) {
return array();
}
if ( ! self::should_show_notice( self::DISMISS_MISSING_SUBS_NOTICE ) ) {
return array();
}
$subscriptions = WC_Helper::get_subscription_list_data();
$missing_subscriptions = array_filter(
$subscriptions,
function ( $sub ) {
return ( ! empty( $sub['local']['installed'] ) && empty( $sub['product_key'] ) );
},
);
// Remove WUM from missing subscriptions list.
$missing_subscriptions = array_filter(
$missing_subscriptions,
function ( $sub ) {
return 'woo-update-manager' !== $sub['zip_slug'];
}
);
if ( ! $missing_subscriptions ) {
return array();
}
$total_missing_subscriptions = count( $missing_subscriptions );
$notice_data = self::get_subscriptions_notice_data(
$subscriptions,
$missing_subscriptions,
$total_missing_subscriptions,
array(
/* translators: 1) product name */
'single_manage' => __( 'You don\'t have a subscription for %1$s. Subscribe to receive updates and streamlined support.', 'woocommerce' ),
/* translators: 1) total expired subscriptions */
'different_subscriptions' => __( 'You don\'t have subscriptions for %1$s Woo extensions. Subscribe to receive updates and streamlined support.', 'woocommerce' ),
),
'missing',
);
$button_link = add_query_arg(
array(
'add-to-cart' => $notice_data['product_ids'],
'utm_source' => 'pu',
'utm_campaign' => 'pu_in_apps_screen_purchase',
),
self::WOO_CART_PAGE_URL
);
if ( in_array( $notice_data['type'], array( 'single_manage', 'multiple_manage' ), true ) ) {
$button_link = add_query_arg(
array(
'add-to-cart' => $notice_data['product_id'],
),
$button_link
);
}
$button_text = __( 'Subscribe', 'woocommerce' );
return array(
'description' => $notice_data['parsed_message'],
'button_text' => $button_text,
'button_link' => $button_link,
);
}
/**
* Get notice information when WCCOM connection is disconnected.
*
* @return string disconnect notice.
*/
public static function get_wccom_disconnected_notice() {
if ( WC_Helper::is_site_connected() ) {
return '';
}
if ( ! self::should_show_notice( self::DISMISS_DISCONNECT_NOTICE, false ) ) {
return '';
}
$user_email = \WC_Helper_Options::get( 'last_disconnected_user_data' )['email'] ?? null;
if ( empty( $user_email ) ) {
return '';
}
return sprintf(
/* translators: 1: Disconnected user email */
__( 'Successfully disconnected from %1$s.', 'woocommerce' ),
$user_email
);
}
/**
* Determine whether a specific notice should be shown to the current user.
*
* @param string $dismiss_notice_meta User meta that includes the timestamp when a store notice was dismissed.
* @param bool $show_after_one_month Show the notices dismissed earlier than one month.
* @return bool True if the notice should be shown, false otherwise.
*/
public static function should_show_notice( $dismiss_notice_meta, $show_after_one_month = true ) {
// Get the current user ID.
$user_id = get_current_user_id();
// Get the timestamp when the notice was dismissed.
$dismissed_timestamp = get_user_meta( $user_id, $dismiss_notice_meta, true );
if ( ! $show_after_one_month ) {
return empty( $dismissed_timestamp );
}
// If the notice was dismissed within the last month, do not show it.
if ( ! empty( $dismissed_timestamp ) && ( time() - $dismissed_timestamp ) < 30 * DAY_IN_SECONDS ) {
return false;
}
// If the notice was dismissed more than a month ago, delete the meta value and show the notice.
if ( ! empty( $dismissed_timestamp ) ) {
delete_user_meta( $user_id, $dismiss_notice_meta );
}
return true;
}
/**
* Get the notice data for missing payment method.
*
* @param bool $allowed_link whether should show link on the notice or not.
* @param int $total_expiring_subscriptions total expiring subscriptions.
*
* @return array the notices data.
*/
public static function get_missing_payment_method_notice( $allowed_link = true, $total_expiring_subscriptions = 1 ) {
$add_payment_method_link = add_query_arg(
array(
'utm_source' => 'pu',
'utm_campaign' => $allowed_link ? 'pu_settings_screen_add_payment_method' : 'pu_in_apps_screen_add_payment_method',
),
self::WOO_ADD_PAYMENT_METHOD_URL
);
$description = $allowed_link
? sprintf(
/* translators: %s: WooCommerce.com URL to add payment method */
_n(
'Your WooCommerce extension subscription is missing a payment method for renewal. Add a payment method to ensure you continue receiving updates and streamlined support.',
'Your WooCommerce extension subscriptions are missing a payment method for renewal. Add a payment method to ensure you continue receiving updates and streamlined support.',
$total_expiring_subscriptions,
'woocommerce'
),
$add_payment_method_link
)
: _n(
'Your WooCommerce extension subscription is missing a payment method for renewal. Add a payment method to ensure you continue receiving updates and streamlined support.',
'Your WooCommerce extension subscriptions are missing a payment method for renewal. Add a payment method to ensure you continue receiving updates and streamlined support.',
$total_expiring_subscriptions,
'woocommerce'
);
return array(
'description' => $description,
'button_text' => __( 'Add payment method', 'woocommerce' ),
'button_link' => $add_payment_method_link,
);
}
}