# Stop Customers Buying the Same Download Twice

> Replaces the purchase button with a "You already own this" link for logged-in customers who bought a download before, and blocks repeat purchases at checkout.

- Type: PHP
- Runs: Run everywhere
- Category: [Easy Digital Downloads](https://wpide.com/library/category/edd/)
- Requires: Easy Digital Downloads
- Tags: edd, purchases, customers, checkout
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/edd-prevent-repeat-purchase/

## Code

```php
add_filter( 'edd_purchase_download_form', function ( $form, $args ) {
    $download_id = (int) ( $args['download_id'] ?? 0 );

    if ( ! $download_id || ! is_user_logged_in() || ! edd_has_user_purchased( get_current_user_id(), $download_id ) ) {
        return $form;
    }

    $history = edd_get_option( 'purchase_history_page' );

    return sprintf(
        '<p class="wpide-edd-owned">%1$s%2$s</p>',
        esc_html( 'You already own this.' ),
        $history ? ' <a href="' . esc_url( get_permalink( $history ) ) . '">' . esc_html( 'Go to your downloads' ) . '</a>' : ''
    );
}, 10, 2 );

add_action( 'edd_checkout_error_checks', function () {
    if ( ! is_user_logged_in() ) {
        return;
    }

    foreach ( (array) edd_get_cart_contents() as $item ) {
        if ( edd_has_user_purchased( get_current_user_id(), $item['id'] ) ) {
            edd_set_error( 'wpide_already_purchased', sprintf( 'You already own %s. Please remove it from your cart.', get_the_title( $item['id'] ) ) );
            return;
        }
    }
} );
```

## Notes

Works for logged-in customers, and downloads with variable prices are checked as a whole.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Stop Customers Buying the Same Download Twice" 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/
