WooCommerce cart is empty after adding products

If the WooCommerce cart is empty after adding products only for guests, while logged-in users can shop normally, guest sessions may not be saving. Add a product in an incognito window and watch the woocommerce_sessions table. If no new rows appear, a short snippet on the woocommerce_set_cart_cookies hook forces WooCommerce to save the session.

woocommerce cart is empty after adding products

The WooCommerce “cart is empty” issue is a session problem where products don’t stay in the cart after customers add them, so the cart page shows empty. In our client’s case, it only affected guest (logged-out) users, while admins and logged-in customers could shop normally, and the cause was that WooCommerce wasn’t saving guest sessions to the woocommerce_sessions table.

There were no PHP errors, no JavaScript errors in the browser console and nothing in the error_log file, even with WP_DEBUG enabled. With no error messages to guide me, it took a couple of hours to find the cause. Below are the fixes I ruled out, the ones that helped other people and the snippet that finally worked.

Solutions I tested and ruled out

Before finding the real cause, I ruled out the usual suspects for an empty WooCommerce cart: caching, error logs, plugin conflicts, the AJAX add to cart setting, the default WooCommerce pages, WooCommerce tools and permalinks. Each one is still worth checking on your store, because any of them can cause the same symptom.

WordPress cache and server-side cache

Caching is the most common cause of a cart that’s empty only for guests, so I checked it first, since the cart worked as expected for logged-in users. I confirmed that no caching plugin was active and running, including mu-plugins (must-use plugins).

Cache problems aren’t always plugin-related. Hosting providers often implement their own server-level caching that can cause similar issues.

Some web hosts, like WP Engine, cache regular pages on the server side, excluding dynamic WooCommerce pages like /my-account/, /cart/ and /checkout/.

I ruled this out by confirming with the client’s hosting provider that no server-side caching was configured.

If you are running Varnish on your server, check the cart functionality by disabling Varnish.

Error logs

Error logs usually point straight to the cause of a broken cart, but this time they were empty. I checked every place an error could show up (see how to find the error in WordPress), and none of them had anything related to the cart or WooCommerce sessions:

  • PHP errors displayed on the page
  • JavaScript errors in the browser console
  • Server error logs in the error_log file after enabling WP_DEBUG

I was unable to find a clue pointing to the root cause of the empty cart issue.

Plugin conflicts and updates

Plugin conflicts or outdated plugins are a common cause of WooCommerce cart issues. I temporarily deactivated all plugins except WooCommerce to see if the cart would function properly. With only WooCommerce active, the problem persisted, which ruled out plugin conflicts in my case.

The site was using an older WooCommerce version due to a payment gateway plugin compatibility issue.

I deactivated the payment plugin and updated WooCommerce to the latest version, but the cart still didn’t work.

This confirmed the issue wasn’t related to outdated plugins or the payment gateway.

Toggle AJAX cart button

The AJAX add to cart setting can break the cart on some themes, so I tested it next. When I checked the theme settings, AJAX add to cart buttons were enabled. To test this out, I disabled the AJAX add to cart button and replaced it with a regular button. Nothing changed.

I even tried the manual way using a URL, replacing the 123 with the actual product ID.

https://yoursite.com/?add-to-cart=123

Still no luck.

On some themes, such as Flatsome, actually enabling the AJAX add to cart buttons might help.

Ensure you test both options.

This is important if you are using other plugins that use AJAX filtering and might conflict with your theme, or other plugins.

WooCommerce default pages

WooCommerce needs its default Cart, Checkout and My account pages assigned in its settings, or the cart can fail to load. I made sure all default WooCommerce pages were set under WooCommerce > Settings > Advanced, and that each one pointed to the right page.

I also checked that the [woocommerce_cart] shortcode (or the Cart block on newer stores) was on the Cart page.

If necessary, delete the existing default WooCommerce pages and regenerate them.

To do this, go to WooCommerce > Status, open the Tools tab, scroll down to Create default WooCommerce pages and click Create pages.

WooCommerce tools

WooCommerce’s built-in tools can clear stored data that sometimes breaks the cart. Using the tools under WooCommerce > Status > Tools, I cleared WooCommerce transients, expired transients and customer sessions, which removes any stale cart or session data saved in the database.

Unfortunately, clearing WooCommerce transients, expired transients, and customer sessions also didn’t solve the issue.

Re-saving permalinks regenerates your rewrite rules, which can fix add to cart requests that fail because of broken routing. It only takes a minute, so it’s worth trying early. Sometimes the .htaccess file contains incorrect rewrite rules that prevent add-to-cart AJAX requests from working.

Using the File Manager of the hosting control panel, I navigated to the public_html (root folder of WordPress installation), renamed the old .htaccess file to .htaccess_old (for backup), then re-saved permalinks at Settings > Permalinks.

This generated a fresh .htaccess file with clean rewrite rules, which can fix routing issues that cause add to cart failures.

However, in my case this didn’t fix the problem either.

Solutions that helped other people

When none of my fixes worked, I looked at what solved the empty cart issue for other store owners. These fixes didn’t work in my case, but they did for others, so they’re worth checking: optimizing the database, matching site URLs and SSL, checking the woocommerce_sessions table and the cart page’s parent setting.

WP-Optimize

Optimizing your database tables can help when they’ve built up overhead over time. Use the WP-Optimize plugin to optimize database tables, but before attempting this, back up your database using the UpdraftPlus plugin, so you can restore it if anything goes wrong.

WordPress site URLs and valid SSL certificate

Mismatched site URLs or an invalid SSL certificate can stop WooCommerce from setting the session cookie that keeps a guest’s cart. Make sure WordPress Address (URL) and Site Address (URL) under Settings > General match, that both start with https://, and that your SSL certificate is valid.

Database table woocommerce_sessions

The woocommerce_sessions table stores guest carts, so a corrupted table can leave the cart empty. One user with a similar add-to-cart issue reported that the table existed in their database, but its structure was corrupted, so guest carts couldn’t be saved.

Using phpMyAdmin or a similar tool in your hosting control panel, you can check the table’s structure.

The key thing to check here is the session_id column, which should be the primary key and also must be set to AUTO_INCREMENT.

In my case, I checked the table structure and it was already as in the screenshot above. However, the cart was still empty after adding products.

But, the importance and necessity of the woocommerce_sessions table gave me an idea of where to look and helped me narrow down the possibilities, as I explain in the solution section below.

Hint: The woocommerce_sessions table stores customer session data, including the cart contents of guest (logged-out) users.

Cart page must not have a parent

A cart page set as a child of another page can break the cart on some stores. Some users who faced the empty cart issue found this helpful, so make sure your cart page doesn’t have a parent page. You can check this in the page settings of the Cart page.

How I solved it

I solved it by checking whether WooCommerce was saving guest sessions at all, and it wasn’t. After a couple of hours on the “empty cart after adding products” issue, with none of the fixes above working, I decided to dig deeper into how WooCommerce handles guest sessions.

Inspired by one user’s suggestion about the woocommerce_sessions database table, I found out that when guest users add products to the cart, new rows should be added to the woocommerce_sessions table, keeping all the temporary cart contents.

Using an incognito Chrome window, I tried adding a few products to the cart while keeping an eye on the woocommerce_sessions table, with phpMyAdmin open in another window.

No rows were added to the table and finally, I found what’s not working!

With this discovery, I did a few tests that helped me pinpoint exactly at what stage WooCommerce was failing to write (save) to the woocommerce_sessions table.

I coded this snippet to force WooCommerce to save guest sessions using the woocommerce_set_cart_cookies hook.

I added it to the client’s site using the Code Snippets plugin and the issue got resolved!

If you have a child theme, you can also add the same code to the bottom of your functions.php file in your theme.

add_action('woocommerce_set_cart_cookies', 'force_save_guest_session', 10, 1);
function force_save_guest_session($set) {
    // If user is not logged in and session exists, force save
    if (!is_user_logged_in() && WC()->session && WC()->session->has_session()) {
        WC()->session->save_data();
    }
}

Conclusion

The key takeaway is that when the WooCommerce cart is empty only for guests, check whether guest sessions are being saved to the woocommerce_sessions table. A seemingly minor configuration issue can break your store’s most basic feature and cascade into a critical problem that directly impacts your business.

In this case, our client lost a significant amount of revenue during a peak season, but managed to get back to business quickly once we identified and resolved the empty cart issue.

Lessons learned:

  • The value of regular monitoring.
  • The importance of keeping a recent and working backup.
  • The need for a systematic troubleshooting approach when issues arise.

If you’re experiencing similar WooCommerce cart problems, remember to check session handling first, review recent plugin updates, think about the last change made before the issue started, verify your caching configuration, and examine any custom code that might interfere with cart functionality.

Most importantly, don’t wait until peak season to test your checkout process thoroughly. Regular testing can catch these issues before they cost you sales.

Our WordPress maintenance plans include regular expert testing of your essential website functionalities, so you can focus on growing your business while we ensure everything works flawlessly.

About the author

Ozgur Sar Avatar