Automattic\WooCommerce\Admin

PluginsHelper::get_expiring_subscription_notice()public staticWC 1.0

Get formatted notice information for expiring subscription.

Метод класса: PluginsHelper{}

Хуков нет.

Возвращает

Массив. notice information.

Использование

$result = PluginsHelper::get_expiring_subscription_notice( $allowed_link );
$allowed_link(true|false)
whether the notice description should include a link.
По умолчанию: true

Код PluginsHelper::get_expiring_subscription_notice() WC 9.3.3

public static function get_expiring_subscription_notice( $allowed_link = true ) {
	if ( ! WC_Helper::is_site_connected() ) {
		return array();
	}

	if ( ! self::$can_show_expiring_subs_notice ) {
		return array();
	}

	if ( ! self::should_show_notice( self::DISMISS_EXPIRING_SUBS_NOTICE ) ) {
		return array();
	}

	$subscriptions          = WC_Helper::get_subscription_list_data();
	$expiring_subscriptions = array_filter(
		$subscriptions,
		function ( $sub ) {
			return ( ! empty( $sub['local']['installed'] ) && ! empty( $sub['product_key'] ) )
					&& ( $sub['active'] || empty( $sub['connections'] ) ) // Active on current site or not connected to any sites.
					&& $sub['expiring']
					&& ! $sub['autorenew'];
		},
	);

	if ( ! $expiring_subscriptions ) {
		return array();
	}

	$total_expiring_subscriptions = count( $expiring_subscriptions );

	// When payment method is missing on WooCommerce.com.
	$helper_notices = WC_Helper::get_notices();
	if ( ! empty( $helper_notices['missing_payment_method_notice'] ) ) {
		return self::get_missing_payment_method_notice( $allowed_link, $total_expiring_subscriptions );
	}

	// Payment method is available but there are expiring subscriptions.
	$notice_data = self::get_subscriptions_notice_data(
		$subscriptions,
		$expiring_subscriptions,
		$total_expiring_subscriptions,
		array(
			/* translators: 1) product name 2) expiry date 3) URL to My Subscriptions page */
			'single_manage'           => __( 'Your subscription for <strong>%1$s</strong> expires on %2$s. <a href="%3$s">Enable auto-renewal</a> to continue receiving updates and streamlined support.', 'woocommerce' ),
			/* translators: 1) product name 2) expiry date 3) URL to My Subscriptions page */
			'multiple_manage'         => __( 'One of your subscriptions for <strong>%1$s</strong> expires on %2$s. <a href="%3$s">Enable auto-renewal</a> to continue receiving updates and streamlined support.', 'woocommerce' ),
			/* translators: 1) total expiring subscriptions 2) URL to My Subscriptions page */
			'different_subscriptions' => __( 'You have <strong>%1$s Woo extension subscriptions</strong> expiring soon. <a href="%2$s">Enable auto-renewal</a> to continue receiving updates and streamlined support.', 'woocommerce' ),
		),
		'expiring',
	);

	$button_link = add_query_arg(
		array(
			'utm_source'   => 'pu',
			'utm_campaign' => 'pu_in_apps_screen_enable_autorenew',
		),
		self::WOO_SUBSCRIPTION_PAGE_URL
	);
	if ( in_array( $notice_data['type'], array( 'single_manage', 'multiple_manage' ), true ) ) {
		$button_link = add_query_arg(
			array(
				'product_id' => $notice_data['product_id'],
				'type'       => 'expiring',
			),
			$button_link
		);
	}

	return array(
		'description' => $allowed_link ? $notice_data['parsed_message'] : preg_replace( '#<a.*?>(.*?)</a>#i', '\1', $notice_data['parsed_message'] ),
		'button_text' => __( 'Enable auto-renewal', 'woocommerce' ),
		'button_link' => $button_link,
	);
}