Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
EDD One Item Per Customer
// Prevent checkout if offer already purchased
add_filter( 'edd_can_checkout', 'wd_limit_purchase' );
function wd_limit_purchase(){
$user_id = get_current_user_id(); // Get the current customer's ID
$downloads = edd_get_users_purchased_products( $user_id );// Get all of the products the customer has purchased in the past
$can_checkout = true; // Allow checkout for now
if ( ! empty( $downloads ) ){ // If the customer hasn't purchased anything before we don't need to go any further.
foreach ( $downloads as $download ){ // Loop through each product the customer has purchased before.
$download_id = $download->ID;
$in_cart = edd_item_in_cart( $download_id );
if( $in_cart == true ) {
$can_checkout = false;
return $can_checkout;

This comment has been minimized.

Copy link

joelaceved commented Sep 29, 2018

Hi @MWhiteley,

I got here from post about this.

I was wondering if you know how to make this code to check all the downloads on a specific category, so every time I add a download to that category I don't have to edit the code with new ID's?

All the best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.