Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prevent duplicate purchases #168

Open
mihaijoldis opened this issue Apr 19, 2022 · 0 comments
Open

Update prevent duplicate purchases #168

mihaijoldis opened this issue Apr 19, 2022 · 0 comments

Comments

@mihaijoldis
Copy link
Contributor

Based on an .org ticket https://wordpress.org/support/topic/plugin-code-from-edd-library-does-not-work/ we should update our snippet to allow Renewals and Upgrades if SL is being used. https://library.easydigitaldownloads.com/checkout/prevent-duplicate-purchases.html

Working code (updated) from @robincornett

function pw_edd_prevent_duplicate_purchase( $valid_data, $posted ) {

	$cart_contents = edd_get_cart_contents();
	foreach ( $cart_contents as $item ) {
		if ( ! empty( $item['options']['is_upgrade'] ) ) {
			continue;
		}
		if ( ! empty( $item['options']['is_renewal'] ) ) {
			continue;
		}
		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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant