X

Limit cart to fixed quantity in Easy Digital Downloads

Depending on what you are selling on your site when using Easy Digital Downloads, you may need to limit the cart to a fixed quantity. This sample snippet limits the cart to one item. However, you can adjust the limit to any specific number that you wish. Just add the snippet to the functions.php of your WordPress theme, and you are ready to go.

function pw_edd_one_item_checkout( $download_id, $options ) {
	if( edd_get_cart_quantity() >= 1 ) {
		edd_empty_cart();
	}
}
add_action( 'edd_pre_add_to_cart', 'pw_edd_one_item_checkout', 10, 2 );

To limit the cart to 9 items, use this snippet:

function pw_edd_one_item_checkout( $download_id, $options ) {
	if( edd_get_cart_quantity() >= 9 ) {
		edd_empty_cart();
	}
}
add_action( 'edd_pre_add_to_cart', 'pw_edd_one_item_checkout', 10, 2 );

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!