As I said in other articles, WooCommerce is a more robust and flexible module, capable of turning wordpress into a Ideal online store for a business at the beginning.
content
For an online store of modest size, woCommerce can be rolled on a “shared hosting”, being able to endure lightly and 5,000 products / 100 orders up to date, if the topic used do not consume many resources and do not abuse other modules (plugins).
Optimization of the source code From the theme (WP Themes), modules (wp plugins) and Optimizing the database There are also two aspects that we have to take a lot of.
I noticed the previous days as an online store of modest dimensions begins to consume a lot of many RAM and CPU resources on a dedicated server generous. This high consumption of resources have led to a default to an “load” Increased on the server and a big time to charge the pages of the evening store.
When we notice an unjustified large Load on a web server, it is good to investigate the causes, before taking any measure.
In the database I noticed that the table “wp_woocommerce_sessions
” It's huge. It was over 6 GB. A huge volume for a table from a database that did not normally exceed 100 MB in total.

This este wp_woocommerce_ssionals?
As we can sense from his name, the table “wp_woocommerce_sessions
” Contains PHP sessions (PHP Sessions).
These sessions are actions of users on the site (or web robots) and most often reach the database through cookies. In the WP_WOOCOMMERCE_SESSions are stored data on the products placed by users in the shopping cart, coupons, transport fees, customer data and many other information related to the product order process.
These sessions are created even whether or not the user is registered in the site and normally they must expire and delete automatically.
Unfortunately, it does not always happen that these sessions are deleted and, in some cases, they remain permanently stored in WP_WOOCOMMERCE_SESSIONS, which makes the table reach a large volume.
How to wipe the table wp_woocommerce_sessions
din SQL?
1. We go to Dashboard → WooCommerce → Status → Tools (tab).
2. We're going down to the option “Clear customer sessions“. Careful! The deletion of the clients sessions involves the deletion of all the products placed by them in the shopping cart. If while deleting these sessions are customers who have products in the basket, they will disappear, and the eventual order will not be completed.
3. Click “Clear” and confirmation the operation.

At this time the table “wp_woocommerce_sessions” It is empty, so all customer shopping sessions have been deleted.
The problem is not solved by far. The SQL WP_WooCommerce_sessions table will gather data in it and by default it will gain proportions again, which is not desirable.
How do we make customer sessions stop permanently in Woocommerce – wp_woocommerce_sessions
?
I showed above how the table can be emptied “wp_woocommerce_sessions” From the database, but the problem will appear again after a few days when client sessions will be gathered.
Before WooCommerce 2.5, customer sessions were captured through cookies, and then saved in WordPress table “wp_options
“.
For larger stores this method has often led to disasters. “wp_options” Being a vital table of WordPress, used by general options and settings. Manual identification and deletion of client sessions stored in wp_options
It was not an easy work.
Woocommerce performance was not the best, and the scalability over time was a sensitive point.
With the launch of WooCommerce 2.5 in 2015, WooCommerce developers have introduced a new Woocommerce -based handling and storage system WP Sessions Manager. This system has led to the appearance wp_woocommerce_sessions
. A dedicated table for customer sessions, which in the database does not interact with other tables. In the case of major errors, the losses should be minimal.
From what I noticed, the online stores launched before WooCommerce 2.5 and which have received constant updates over time, have some problems regarding the automatic deletion of the client sessions. It is most likely about a bug on a newer version of Woocommerce 2.5 or a WordPress / Woocommerce plugin that has not kept up with the updates.
In my case it was a conflict with a function added in the file functions.php
of the theme, and which prevent automatic deletion after an expired sessions of woocommerce_sessions
.
If you are experiencing such a problem, you must carefully investigate all possible causes. SQL error, SQL persecutions, Cron Job, conflicts with other plugins and last but not least check your changes in code over time.
I saw that WooCommerce offers for only $ 29 a plugin capable of administering customer's. “Clear Cart and Sessions for WooCommerce“. Of course, besides the programmed deletion of the sessions, the module has several tools that could be helpful.
A simpler option of programmed deletion a “woocommerce_sessions
” at one day intervals, is the displacement with the next code in functions.php
:
// clean cart every day
if (!wp_next_scheduled('cron_wc_clean_cart')) {
wp_schedule_event( time(), 'daily', 'cron_wc_clean_cart' );
}
add_action ( 'cron_wc_clean_cart', 'wc_clean_session_cart' );
function wc_clean_session_cart() {
global $wpdb;
$wpdb->query( "TRUNCATE {$wpdb->prefix}woocommerce_sessions" );
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';" );
wp_cache_flush();
}
Leave a comment if you need help or have another solution.
I have no way to erase the data weighs 500Mb and I have 1000Mb limit to the minute of erase everything is completely filled…Some solution?