WC_Tracks_Client::get_anon_id()
Grabs the user's anon id from cookies, or generates and sets a new one
Method of the class: WC_Tracks_Client{}
No Hooks.
Return
String
. An anon id for the user
Usage
$result = WC_Tracks_Client::get_anon_id();
WC_Tracks_Client::get_anon_id() WC Tracks Client::get anon id code WC 7.7.0
public static function get_anon_id() { static $anon_id = null; if ( ! isset( $anon_id ) ) { // Did the browser send us a cookie? if ( isset( $_COOKIE['tk_ai'] ) ) { $anon_id = sanitize_text_field( wp_unslash( $_COOKIE['tk_ai'] ) ); } else { $binary = ''; // Generate a new anonId and try to save it in the browser's cookies. // Note that base64-encoding an 18 character string generates a 24-character anon id. for ( $i = 0; $i < 18; ++$i ) { $binary .= chr( wp_rand( 0, 255 ) ); } // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode $anon_id = 'woo:' . base64_encode( $binary ); } } return $anon_id; }