WordPress at Your Fingertips
function is not described

WC_Tracks_Client::maybe_set_identity_cookie() public WC 1.0

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

{} It's a method of the class: WC_Tracks_Client{}

No Hooks.

Return

null. Nothing.

Usage

$result = WC_Tracks_Client::maybe_set_identity_cookie();

Code of WC_Tracks_Client::maybe_set_identity_cookie() WC 5.8.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 );
	}
}