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.
Opens WPIDE on
Code
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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.