• Resolved kiberchaka

    (@kiberchaka)


    I am trying to create a plugin for WooCommerce that stores some value into $_SESSION[‘myVar’] before payment process and get it on Thank You Page back. Everything works fine, but when I use a gateway, that makes a callback with POST info about payment to http://exemple.com/wc-api/my_gateway the $_SESSION[‘myVar’] becomes empty and I can’t get value from it on the Thank You Page.

    How I did it:

    // Reg. the session   
    add_action( 'init', __CLASS__ . '::register_session' );
    
    public static function register_session() {
    
        if( !session_id() ) {
            session_start();
        }
    
    }
    
    // Set the session variable before payment
    $_SESSION['myVar'] = 'my value';
    
    // Trying to get the session value after payment
    echo $_SESSION['myVar']; // NULL

    The process is simple: user clicks Pay button, it redirects him to a bank url + sends order info to the bank. The bank process the payment and redirects the user to special API page exemple.com/wc-api/my_gateway + sends POST data array about payment there. I don’t understand why while this the session variable is being deleted.

    Thank you!

    • This topic was modified 3 years, 1 month ago by kiberchaka.
    • This topic was modified 3 years, 1 month ago by kiberchaka.
    • This topic was modified 3 years, 1 month ago by kiberchaka.
    • This topic was modified 3 years, 1 month ago by kiberchaka.
    • This topic was modified 3 years, 1 month ago by kiberchaka.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Session variable disappears after callback to WooCommerce gateway API link’ is closed to new replies.