leolee10
leolee10

Reputation: 3

Wordpress how to use session ? I want to use Shopping Cart

I want to develop online order & shopping cart. My solution is use Session to save user's carts. But Wordpress not provide Session. Have any solution to develop that function?

Upvotes: 0

Views: 695

Answers (1)

drew010
drew010

Reputation: 69957

WordPress doesn't use sessions so you can either start one yourself, or consider creating a database table for storing shopping cart contents and instead use the database.

If you want to start a session, your plugin should call add_action using init as the hook and in your function call, use the code:

if ( session_id() == '' || (function_exists('session_status') && PHP_SESSION_NONE == session_status()) ) {
    // no session has been started yet
    session_start();
}

That code will start a session early on in the WordPress request cycle so you can then use it in your plugin to store shopping cart data in the session.

Upvotes: 1

Related Questions