---
title: Deleting expired shopping carts from the database
related:
  - https://docs.kentico.com/13/configuring-xperience/scheduling-tasks.md
  - https://docs.kentico.com/13/configuring-xperience/scheduling-tasks/reference-scheduled-task-properties.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

When [customers](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/customers.md) add [products](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/products.md) to their shopping carts and then leave the site without finishing their purchases, the shopping cart is saved in the database along with the products in the cart. This can cause bloating of your database and in the end, it can slow down the whole website.

To prevent bloating of the database:

1. [Set the number of days after which the system considers shopping carts as expired](#setting-the-number-of-days-after-which-shopping-carts-are-considered-expired).
2. [Set a regularly launched task that removes the shopping carts from the database.](#configuring-a-scheduled-task-that-deletes-old-shopping-carts)

## Setting the number of days after which shopping carts are considered expired

As with most of the e-commerce settings, you can set the time after the shopping carts are considered as old for [the current site or globally for all your sites](https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/choosing-site-or-global-e-commerce-configuration.md). If you run multiple sites on your instance and want all sites to use the same number of days, use global settings. Otherwise, we recommend that you choose site settings.

1. Open the **Store configuration** application (if you want to specify the setting for the current site) or the **Multistore configuration** application (if you want to specify the setting globally).
2. In the **Shopping cart**category of the **Store configuration -> General** tab, configure the **Clear content of old shopping cart after (days)** setting:

   - Clear the _Inherit from global settings_ option (only if you work in the **Store configuration** application).
   - Type the desired number of days after which shopping carts should be considered as old and should be deleted, for example _30_.
3. Click **Save**.

The system updates the settings. Any [scheduled tasks](https://docs.kentico.com/13/configuring-xperience/scheduling-tasks.md) working with this setting operate with the specified number of days.

## Configuring a scheduled task that deletes old shopping carts

1. Open the **Scheduled tasks** application.
2. In the **Site** selector, select the desired site (if you want to create the scheduled task for a specific site) or leave the _(global)_ option (if you want to create the scheduled task [globally](https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/choosing-site-or-global-e-commerce-configuration.md)).
3. Click **New task**.
4. Enter the following properties:

   - **Task display name**: Clear content of old shopping carts
   - **Task provider**:
     - _Assembly name_: CMS.Ecommerce
     - _Class_: CMS.Ecommerce.ShoppingCartCleaner
   - **Task enabled**: Yes (selected)
5. Enter the [other properties](https://docs.kentico.com/13/configuring-xperience/scheduling-tasks/reference-scheduled-task-properties.md) according to your needs.
6. Click **Save**.

The system now clears the database from the shopping carts of the unfinished purchases.
