X

How to Add Min or Max Total Purchase Amount in Easy Digital Downloads

Snippets by IsItWP

Are you looking for a way to add minimum or maximum total purchase amount in Easy Digital Downloads (EDD)? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add minimum or maximum total purchase amount in Easy Digital Downloads.

By default, the maximum purchase amount is set to 100 in EDD. Any purchase above the maximum threshold will return an error. You can change the amount and the error message per your preference.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

function pw_edd_limit_total_purchase( $valid_data, $post_data ) {
	
	if( edd_get_cart_total() > 100 ) {
		edd_set_error( 'too_much', 'You cannot purchase that much at one time.' );
	}

}
add_action( 'edd_checkout_error_checks', 'pw_edd_limit_total_purchase' );

Instead of maximum amount, if you want to set a minimum total purchase amount, then replace the following line if( edd_get_cart_total() > 100 ) { with if( edd_get_cart_total() < 10 ) {.

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don't accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 11 best WordPress quiz plugins to boost user engagement and how to secure your WordPress forms with password protection.

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!