WC_Helper_Updater::get_renew_link │ private static │ WC 11.2.0

Cart link that renews one specific subscription.

A plain add-to-cart link would buy a new subscription instead. This is the same link the My Subscriptions screen and the product usage notice use. Renewing needs the product key and the order ID; a record missing either gets the add-to-cart link, which still works.

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

Хуков нет.

Возвращает

string.

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

$result = WC_Helper_Updater::get_renew_link( $subscription, $campaign ): string;
$subscription(массив) (обязательный)
Subscription record from the WooCommerce.com API.
$campaign(строка) (обязательный)
utm_campaign value for the link.

Список изменений

С версии 11.2.0 Введена.

Код WC_Helper_Updater::get_renew_link() WC 11.2.1

private static function get_renew_link( array $subscription, string $campaign ): string {
	$product_id  = $subscription['product_id'];
	$product_key = $subscription['product_key'] ?? '';
	$order_id    = $subscription['order_id'] ?? '';

	// The same shape check filter_valid_subscriptions() applies to the product ID.
	$has_order_id = ( is_int( $order_id ) || ( is_string( $order_id ) && ctype_digit( $order_id ) ) ) && 0 < (int) $order_id;

	if ( ! is_string( $product_key ) || '' === $product_key || ! $has_order_id ) {
		return add_query_arg(
			array(
				'add-to-cart'  => $product_id,
				'utm_source'   => 'pu',
				'utm_campaign' => $campaign,
			),
			PluginsHelper::WOO_CART_PAGE_URL
		);
	}

	return add_query_arg(
		array(
			'renew_product' => $product_id,
			'product_key'   => $product_key,
			'order_id'      => $order_id,
			'utm_source'    => 'pu',
			'utm_campaign'  => $campaign,
		),
		PluginsHelper::WOO_CART_PAGE_URL
	);
}