Skip to content

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

@mihaijoldis

Description

@mihaijoldis

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 );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions