wc_setcookie( string $name, string $value, integer $expire, bool $secure = false, bool $httponly = false )

Set a cookie – wrapper for setcookie using WP constants.


Description Description


Parameters Parameters

$name

(Required) Name of the cookie being set.

$value

(Required) Value of the cookie.

$expire

(Required) Expiry of the cookie.

$secure

(Optional) Whether the cookie should be served only over https.

Default value: false

$httponly

(Optional) Whether the cookie is only accessible over HTTP, not scripting languages like JavaScript. @since 3.6.0.

Default value: false


Top ↑

Source Source

File: includes/wc-core-functions.php

function wc_setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) {
	if ( ! headers_sent() ) {
		setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'woocommerce_cookie_httponly', $httponly, $name, $value, $expire, $secure ) );
	} elseif ( Constants::is_true( 'WP_DEBUG' ) ) {
		headers_sent( $file, $line );
		trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine
	}
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.