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
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);
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.
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' );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With