WC_Site_Tracking::set_tracking_cookie
Sets a cookie for tracking purposes, but only if tracking is enabled/allowed.
Method of the class: WC_Site_Tracking{}
No Hooks.
Returns
true|false
. If setting the cookie was attempted (will be false if tracking is not allowed).
Usage
$result = WC_Site_Tracking::set_tracking_cookie( $cookie_key, $cookie_value, $expire, $secure, $http_only ): bool;
- $cookie_key(string) (required)
- The key of the cookie.
- $cookie_value(string) (required)
- The value of the cookie.
- $expire(int)
- Expiry of the cookie.
- $secure(true|false)
- Whether the cookie should be served only over https.
Default: false - $http_only(true|false)
- Whether the cookie is only accessible over HTTP.
Default: false
Changelog
Since 9.2.0 | Introduced. |
WC_Site_Tracking::set_tracking_cookie() WC Site Tracking::set tracking cookie code WC 9.9.3
public static function set_tracking_cookie( string $cookie_key, string $cookie_value, int $expire = 0, bool $secure = false, bool $http_only = false ): bool { if ( self::is_tracking_enabled() ) { wc_setcookie( $cookie_key, $cookie_value, $expire, $secure, $http_only ); return true; } return false; }