Home Forums WoodMart support forum PHP notices header already sent

PHP notices header already sent

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #147880

    metuza
    Participant

    I have 3 sites, 1 running on 4.1.0 and second on v4.0.4 and both gives me this notice in debug log:

    [01-Oct-2019 14:40:02 UTC] PHP Notice: wp_woocommerce_session_baea78ae712607fb6687853a2c9c06b2 cookie cannot be set – headers already sent by /wp-content/plugins/wordpress-seo/inc/class-wpseo-utils.php on line 1194 in /wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 887
    [01-Oct-2019 14:40:11 UTC] PHP Notice: wp_woocommerce_session_baea78ae712607fb6687853a2c9c06b2 cookie cannot be set – headers already sent by /wp-includes/general-template.php on line 3137 in /wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 887

    My third site on v3.8.2 does not have these notices. All sites has mostly the same setup and plugins. And i did a test on my v4.0.4 site, reverted back to 3.8.2 and all issues/notices dissapeared. So it seems like there is an conflict with later versions.

    Any idea?

    Brgds
    Rune

    #147928

    metuza
    Participant

    I have now narrowed down the issue and after deactivating ALL plugins and tested 3 different theme versions (woodmart) i still get the notices but now they look like this:

    [01-Oct-2019 16:51:55 UTC] PHP Notice: wp_woocommerce_session_59f9adf68b3deeb3d144141c2fae7308 cookie cannot be set – headers already sent by /wp-includes/class.wp-scripts.php on line 209 in /wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 887

    The above notice appear in v4.0.4 and 4.1.0 but not in v3.8.2 or any standard themes.

    Brgds
    Rune

    #147962

    Artem Temos
    Keymaster

    Hi,

    These notices appear in the WooCommerce plugin when we use their cookies mechanisms for our wishlist and compare. We really don’t know in which exactly situations they appear and how to avoid them. But they are absolutely harmless and you can ignore them.

    Kind Regards

    #147991

    metuza
    Participant

    Oki, its just annoying when using debug-log actively as it fills up with thousands of lines in a few days.

    I have found that they appear only in archive pages and they appear even if i have deactivated wishlist, compare, header banner and promo popup.

    #148011

    Artem Temos
    Keymaster

    Do you have WP_DEBUG mode enabled in the file wp-config.php? Try to turn it off.

    #148012

    metuza
    Participant

    Yes i have it enabled because i am using it actively when building websites. If i turn it of i will not be able to follow up on any issues during my development.

    Rune

    #148027

    Artem Temos
    Keymaster

    Yes, but on live website, this option should be turned on. You need to do your development on a staging environment.

    #148058

    metuza
    Participant

    Development and testing is always done in my staging sites but sometimes, like yesterday, i had to debug a payment gateway issue which only appeared for some users on specific browsers then i had to enable it in my live site a few hours. But log was difficult to read as the record i was looking for was in between 2-3000 lines of this cookie notices. It adds up extremely fast in my live site because it has high traffic.

    It is just annoying nothing else 😉

    Rune

    #148063

    Artem Temos
    Keymaster

    We will try to fix these notices but currently, we don’t have a solution to this, unfortunately.

    #148084

    metuza
    Participant

    I just did a test in /wp-content/themes/woodmart/inc/integrations/woocommerce/functions.php

    I commented out the add_action as below and issue dissapeared. isn it a little late to set session cookie “woodmart_before_shop_page” as other html has already been output?

    if( ! function_exists( 'woodmart_set_customer_session' ) ) {
    
    	//add_action( 'woodmart_before_shop_page', 'woodmart_set_customer_session', 10 );
    
    	function woodmart_set_customer_session() {
    		if( ! function_exists( 'WC' ) ) return;
    		if ( WC()->version > '2.1' && ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) ) :
    			WC()->session->set_customer_session_cookie( true );
    		endif;
    	}
    
    }
    #148102

    metuza
    Participant

    Changed the above mentioned action:

    add_action( 'woodmart_before_shop_page', 'woodmart_set_customer_session', 10 );
    
    to
    
    add_action( 'woocommerce_init', 'woodmart_set_customer_session' );

    and everything seems to work just fine, no php notices, and user session is set and ok.

    #148100

    Artem Temos
    Keymaster

    There is some problem with this code if we use another hook for that. It has to be there to work smoothly.

    #148211

    metuza
    Participant

    Can you say anything about what kind of problems? I have now tested my site using the other hook for the last 12 hours and have to say that my site never has been working so smooth before.

    I have for a few months had some wierd problems with a payment gateway not registering address info correctly so orders has been cancelled. This is used as a quick-pay where user does not enter any information as everything is stored in their smartphone, but the reporting back to orders has been messed up. This is now working perfectly fine.

    Also had some wierd redirects when clicking the category links in header titles, always showing the icon-roller first the opened the page which i actually left before it opens the new page. This is now working perfectly fine.

    Now tested login/logout, wishlist, compare, promo banners, promo popup, header banner + + + and everything seems to work perfectly fine so it would be interessting to test for the issues you know about.

    Brgds
    Rune

    #148265

    metuza
    Participant

    Sorry, forgot to mention that also this line:

    if( ! function_exists( 'WC' ) ) return;

    Needs to be changed to this:

    if( ! is_shop() || ! function_exists( 'WC' ) ) return;

    To avoid possible unconditional fatal errors.

    Brgds
    Rune

    #148239

    Artem Temos
    Keymaster

    OK, you can keep the fix in your child theme and check how it works.

Viewing 15 posts - 1 through 15 (of 15 total)