Created
November 8, 2015 21:16
-
-
Save SeanChDavis/bbedcaf76a93c75de010 to your computer and use it in GitHub Desktop.
EDD Already Purchased Item(s)
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
<?php // DO NOT COPY THIS LINE | |
/** | |
* Prevents logged-in customers from purchasing an item twice | |
*/ | |
function pw_edd_prevent_duplicate_purchase( $valid_data, $posted ) { | |
$cart_contents = edd_get_cart_contents(); | |
foreach( $cart_contents as $item ) { | |
if( edd_has_user_purchased( get_current_user_id(), $item['id'] ) ) { | |
edd_set_error( 'duplicate_item', 'You have one or more items in the cart that have already been purchased.' ); | |
} | |
} | |
} | |
add_action( 'edd_checkout_error_checks', 'pw_edd_prevent_duplicate_purchase', 10, 2 ); | |
/** | |
* Add notice next to each item in cart that has been purchased | |
*/ | |
function sd_already_purchased_notice( $item ) { | |
if ( edd_has_user_purchased( get_current_user_id(), $item['id'] ) ) { | |
echo ' <small>(already purchased)</small>'; | |
} | |
} | |
add_action( 'edd_checkout_cart_item_title_after', 'sd_already_purchased_notice' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment