Where do the cart details are stored in database?

I am new to woo-commerce, can anyone please let me know where the cart items are stored in Database. which tables have cart details?

2 Answers
2

Various information about cart are stored by woocmmerce by two ways:

  1. In $woocommerce object( About session , cart info, subtotal etc)
  2. In database table named persistent_cart which is dynamic … it will get destroyed as soon as checkout is done.

So , now how to access all this info …
For the 1st kind just declare global $woocommerce object and use below code to see all details

global $woocommerce;
echo "<pre>";
print_r($woocommerce);
exit;

For the 2nd kind you have to fetch data from table.. therefore first declare $wpdb wordpress object and write sql query to get result
one thing to note here is… data is stored in serialize manner in woocommerce_persistent_cart table so you have to unserialize it before using it
only then you can use it. Below is code to get cart information from table

global $wpdb;
$array = $wpdb->get_results("select meta_value from ".$wpdb->prefix."usermeta where meta_key='_woocommerce_persistent_cart'");
//print_r($array);
$data =$array[0]->meta_value;
$de=unserialize($data); 

Leave a Comment