Home Forums WoodMart support forum Wishlist out of sync when logging in/out

Wishlist out of sync when logging in/out

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #628636

    tomass
    Participant

    When logging in and out and adding/removing products while between the two states it seems like the wishlist sometimes gets out of sync

    #628711

    Artem Temos
    Keymaster

    Hello,

    We checked the video and see that it works as expected. Logged-in and logged-out wishlists are separate. Could you please clarify what is wrong there?

    Kind Regards

    #628723

    tomass
    Participant

    Yeah the wishlists are separate but at 2:00 you can see that the guest wishlist counter (the number in header) starts getting overwritten to 2 instead of 3 due to logged in wishlist count being 2

    #628847

    Artem Temos
    Keymaster

    Try to add the following PHP code snippet to the child theme functions.php file to fix this

    add_action('wp_logout', function () {
    	$cookie_storage  = new XTS\WC_Wishlist\Cookies_Storage();
    	$cookie_products = $cookie_storage->get_all();
    
    	$cookie_name_count = 'woodmart_wishlist_count';
    
    	if ( is_multisite() ) {
    		$cookie_name_count .= '_' . get_current_blog_id();
    	}
    
    	if ( empty( $cookie_products ) ) {
    		woodmart_set_cookie( $cookie_name_count, 0 );
    	} else {
    		woodmart_set_cookie( $cookie_name_count, count( $cookie_products ) );
    	}
    });

Tagged: 

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