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

New snippet to restrict purchases for the same active subscription again #148

Open
mihaijoldis opened this issue Dec 18, 2020 · 0 comments

Comments

@mihaijoldis
Copy link
Contributor

Was requested by a customer that if the user has an active subscription for Download X he should not be allowed to buy it again.
Code that seems to work:

function pw_edd_recurring_limit_one_subscription( $valid_data, $post_data ) {

	if( ! is_user_logged_in() ) {
		return;
	}

	$subscriber = new EDD_Recurring_Subscriber( get_current_user_id(), true );
	$cart_contents = edd_get_cart_contents();

	foreach( $cart_contents as $item ) {
		if( $subscriber->has_active_product_subscription( $item['id'] ) ) {
			edd_set_error( 'duplicate_item', 'You have already purchased this item so may not purchase it again' );
		}
	}

}
add_action( 'edd_checkout_error_checks', 'pw_edd_recurring_limit_one_subscription', 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