Created
July 23, 2018 18:03
-
-
Save mwhiteley16/460d3978d8c60177bdbded943bbfcc26 to your computer and use it in GitHub Desktop.
EDD One Item Per Customer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @MWhiteley,
I got here from scottdeluzio.com 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?
Thanks
All the best.