I have 2 sites wordpressA and wordpressB.
wordpressB is actually hidden. Only wordpressA has access to it.
wordpressB also runs a woocommerce.

I run functions from A inside B through curl where I pass a functionName as a string and execute it in B.

Everything seams to work well for what concerns retrieving any kind of info except for stuff related to user session. (because I’m not logged in and not accessing any page)

What I would like to do is add and remove to/from shopping CART.

ANY OF YOU KNOW HAW TO SIMULATE A LOGGIN IN functions.php?

From what I read, when physically logged in, WP gives you a session key.

This is what I have so far:

function e_user_login($opp){

    global $woocommerce;

    wp_logout();

    wp_clear_auth_cookie();

    $user = e_get_user_by_id($opp);

    $creds = array();

    $creds['user_login'] = $user->data->user_login;

    $creds['remember'] = true;

    add_filter( 'authenticate', 'allow_programmatic_login', 10, 3 ); //so I can logg in without password.

    wp_signon( $creds, false );  

    remove_filter( 'authenticate', 'allow_programmatic_login', 10, 3 );

    wp_set_auth_cookie($opp['id'],1,0);

    wp_set_current_user($opp['id'], $user->data->user_login);

    session_start();

    $woocommerce->cart->add_to_cart($opp['prod'],$opp['qt']);

    return $woocommerce->cart->get_cart();

}

function allow_programmatic_login( $user, $username, $password ) {
    return get_user_by( 'login', $username );
}

Read more here: Simulate physical login to wordpress and woocommerce without API


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: