WC_Tracks_Client::maybe_set_identity_cookie()public staticWC 1.0

Check if identity cookie is set, if not set it.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$result = WC_Tracks_Client::maybe_set_identity_cookie();

Код WC_Tracks_Client::maybe_set_identity_cookie() WC 8.7.0

public static function maybe_set_identity_cookie() {
	// Do not set on AJAX requests.
	if ( Constants::is_true( 'DOING_AJAX' ) ) {
		return;
	}

	// Bail if cookie already set.
	if ( isset( $_COOKIE['tk_ai'] ) ) {
		return;
	}

	$user = wp_get_current_user();

	// We don't want to track user events during unit tests/CI runs.
	if ( $user instanceof WP_User && 'wptests_capabilities' === $user->cap_key ) {
		return false;
	}
	$user_id = $user->ID;
	$anon_id = get_user_meta( $user_id, '_woocommerce_tracks_anon_id', true );

	// If an id is still not found, create one and save it.
	if ( ! $anon_id ) {
		$anon_id = self::get_anon_id();
		update_user_meta( $user_id, '_woocommerce_tracks_anon_id', $anon_id );
	}

	// Don't set cookie on API requests.
	if ( ! Constants::is_true( 'REST_REQUEST' ) && ! Constants::is_true( 'XMLRPC_REQUEST' ) ) {
		wc_setcookie( 'tk_ai', $anon_id );
	}
}