• Respected sir/madam,

    Thanks for the beautiful cart plugin. My issue is as follows.

    1) After adding items in the cart if I log in then items added before are getting lost (Even though the account’s cart is empty).
    2) How to concatenate items added in the cart before login and items already existing in the account’s cart after login.

    Before login https://pasteboard.co/JTLQQ1t.png
    After login https://pasteboard.co/JTLR4Ge.png

    Please let me know in case of any queries.

    Regards & Thanks
    Indiano

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author WPClever

    (@wpclever)

    Hi @thesaintindiano

    Please add this snippet to current-theme (or child-theme) / functions.php

    add_action( 'wp_login', 'woofc_get_cart_after_login', 99, 2 );
    function woofc_get_cart_after_login( $user_login, $user ) {
    	$saved_cart = get_user_meta( $user->ID, '_woocommerce_persistent_cart_' . get_current_blog_id(), true );
    	$cart       = WC()->session->cart;
    	$merge_cart = array_merge( $cart, $saved_cart['cart'] );
    
    	if ( ! empty( $merge_cart ) ) {
    		$saved_cart['cart'] = $merge_cart;
    		update_user_meta( $user->ID, '_woocommerce_persistent_cart_' . get_current_blog_id(), $saved_cart );
    	}
    }
    Thread Starter thesaintindiano

    (@thesaintindiano)

    Hi @wpclever,

    Thanks for the message. I have added the code using the code snippets plugin and the problems still remain. Should I add the above code to functions.php? (Code snippet is doing the same) Please let me know in case of any queries.

    Regards
    Indiano

    Plugin Author WPClever

    (@wpclever)

    Yes, please try to add this snippet to the theme/functions.php on the dev/staging site first.

    Thread Starter thesaintindiano

    (@thesaintindiano)

    Hi there,

    I added in the functions.php file and still the same. I will attach test user credentials for you to check if you need them.

    Website: https://bhutatva.com/
    1) Add any product in the cart
    2) Login with
    username: bhutatva-test-ext5tjrSd4Z
    password: DpAiv8pjzFg(3#S6Phglufw2
    3) See the cart items if added or merged (already in the cart before)

    Functions.php
    https://pasteboard.co/JVhZtg2.png

    Regards & Thanks
    Indiano

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Items added in cart getting lost after login’ is closed to new replies.