Replies: 0
Good day, i download and installed the following code snippet to prevent users from adding duplicate products during checkout however it does not work properly.
1) If the user tries to renew before the expiration date a warning comes up saying that you have already purchased this product and to use the upgrade links to upgrade to the next level. But this has nothing to do with adding the product to the cart on the initial purchase. It has to do with renewing an existing product.
How can this be changed to EXCLUDE users who are;
1) Renewing
2) Upgrading to the next variable pricing structure
3) Prevent loggin/logged out users from purchasing twice
`/*
* Plugin Name: Easy Digital Downloads – Prevent Duplicate Purchases
* Description: Prevents logged-in customers from purchasing an item twice.
* Author: Easy Digital Downloads
* Author URI: https://easydigitaldownloads.com/
* Version: 1.0
*/
function pw_edd_prevent_duplicate_purchase( $valid_data, $posted ) {
$cart_contents = edd_get_cart_contents();
foreach( $cart_contents as $item ) {
if( edd_has_user_purchased( get_current_user_id(), $item[‘id’] ) ) {
edd_set_error( ‘duplicate_item’, ‘You have already purchased this item so may not purchase it again. If you want to upgrade, click on My Licenses and select the next upgrade level!’ );
}
}
}
add_action( ‘edd_checkout_error_checks’, ‘pw_edd_prevent_duplicate_purchase’, 10, 2
);