# Allow Only One Download in the EDD Cart

> Empties the Easy Digital Downloads cart before a new item is added, so each purchase contains a single download, which suits licence or membership sales.

- Type: PHP
- Runs: Run everywhere
- Category: [Easy Digital Downloads](https://wpide.com/library/category/edd/)
- Requires: Easy Digital Downloads
- Tags: edd, cart, limits
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/edd-single-item-cart/

## Code

```php
add_action( 'edd_pre_add_to_cart', function ( $download_id ) {
    $contents = edd_get_cart_contents();

    if ( ! $contents ) {
        return;
    }

    foreach ( $contents as $item ) {
        if ( (int) $item['id'] !== (int) $download_id ) {
            edd_empty_cart();
            return;
        }
    }
} );
```

## Notes

Adding the same download again simply keeps it in the cart.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Allow Only One Download in the EDD Cart" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
