Header menu


Tuesday, 15 October 2013

How cart details(product_id,prices,quantity etc) are stored by woocommerce ?

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>";

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'");
$data =$array[0]->meta_value;