• Resolved alx359

    (@alx359)


    Have WP_DEBUG enabled. Since the last update (4.3.1), I’m getting the debug.log steadily filled with these:

    PHP Notice: wp_woocommerce_session_e03d1d1db669f41e7a75325c178ba160 cookie cannot be set - headers already sent by on line 0 in /wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 1039

    After some debugging, the premature headers seem to originate from /wp-cron.php.

    The fix that’s working for me is in woocommerce\includes\wc-core-functions.php line 1036 to add a check for when DOING_CRON (and think perhaps for DOING_AJAX, too):

    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' ) ) {
        } elseif ( Constants::is_true( 'WP_DEBUG' ) && ! defined( 'DOING_CRON' ) && ! defined( 'DOING_AJAX' ) ) { 
    #<--
    		headers_sent( $file, $line );
    		trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘cookie cannot be set’ is closed to new replies.