Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use session in woocommerce pages like we use normal php session?

Tags:

woocommerce

How can i store my data in woocommerce session and used it anywhere in woocommerce pages(like thankyou page,processing mail page). 2nd i just have to send a unique code in woocommerce email(both admin and user). How to do it? Thanks in advance

like image 875
Anil Tomar Avatar asked Nov 29 '14 06:11

Anil Tomar


People also ask

How do you set a session in WooCommerce?

How to set a Session variable in WooCommerce? Use WC()->session->set() method to set a session variable. WC()->session->set('sess_variable_name', $data);

Does WordPress use PHP sessions?

WordPress core does not use PHP sessions, but sometimes they are required by your use-case, a plugin or theme. This plugin implements PHP's native session handlers, backed by the WordPress database.


1 Answers

For using session you can do

// Test if your are on Back Office, WC()->session isn't set
if( !is_admin() ){
    $data = 'test';
    WC()->session->set( 'name_for_your_data' , $data );

    $retrive_data = WC()->session->get( 'name_for_your_data' );
}
like image 180
XciD Avatar answered Oct 28 '22 23:10

XciD