0

have a WordPress store and I built it using the WooCommerce plugin. Today, I encountered an issue with my site that I need help resolving. The problem is as follows:

Imagine a scenario where a logged-in user adds a few products to their cart. Two days later, they return to my site but unknowingly log out. They then add another product to their cart, but suddenly realize that they are not logged in. They then proceed to log in to their account, but upon doing so, their new cart overwrites their previous cart. I found my issue, I wrote a plugin for login and register, and I understand this issue appeared for this plugin, I used the wp_set_current_user function for logged-in users please see this function and say where is my problem my code is:

add_action('wp_ajax_SubmitPass', 'SubmitPass');
add_action('wp_ajax_nopriv_SubmitPass', 'SubmitPass');
function SubmitPass()
{
    global $wpdb;
    $UserID = intval($_POST['UserID']);
    $UserPass = htmlspecialchars($_POST['UserPass']);
    $User = $wpdb->get_results("SELECT `user_pass` FROM `wp_users` WHERE `ID` = $UserID");
    $UserPassHash = $User[0]->user_pass;
    if (wp_check_password($UserPass, $UserPassHash, $UserID)) {
        wp_set_current_user($UserID); // Set the current user detail
        wp_set_auth_cookie($UserID); // Set auth details in cookie
        if (get_user_meta($UserID, 'UserPhone', true) == '') {
            echo 'GoToGivePhone';
        } else {
            echo 'OK';
        }
    } else {
        echo 'incorrect';
    }
    die(0);
}
1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Apr 24 at 19:22

0