Have you noticed that your WooCommerce site is running slow? Before asking your web host to increase resources read this article.
WooCommerce stores in wp_options customer’s shopping cart information. As a result if you have many number of visitors in your website wp_options might become really big. This affects your website’s performance.
Another reason for large number of wc_session records is robots. This happens because many search engines crawl your website plenty times during the day.
For example a search engine visits a link such as the following:
This url adds the product with ID 11 to cart, which means that a wc_session is going to be created and stored in wp_options. Imagine what happens when you have thousands of products in your eshop and search engines crawls your website all the time.
In order to avoid this very usual scenario simply add the following lines in your robots.txt file
This will prevent search engines to crawl urls that contain add-to-cart parameters and won’t add wc_session records in wp_options.
Which option is the best?
In the end, no matter how big your site is or how many visitors you have per day, wp_options sooner or later will grow big some time.
You should really take into consideration which option is the best to avoid such an experience. I would suggest to set up a cron job in order to clear wc_sessions. It’s on you to decide how frequently this job will be executed. For example in a client’s website with 3000 products and about 1000 visitors per day I’ve setup this cron job to run twice a day.
Here is the MySQL script to clear wc_sessions
DELETE FROM wp_options
WHERE option_name LIKE '_wc_session_%' OR option_name LIKE '_wc_session_expires_%'
I am going to talk in another post about setting up effective cron jobs in WordPress