Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Make woocommerce not allow a product user has purchased before to be purchased again
// posted by Robin Scott - prevent user adding item to cart if they bought it before...
add_filter('woocommerce_add_to_cart_validation','sd_bought_before_woocommerce_add_to_cart_validation',20, 2);
function sd_bought_before_woocommerce_add_to_cart_validation($valid, $product_id){
$current_user = wp_get_current_user();
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id)) {
wc_add_notice( __( 'ERROR MESSAGE GOES HERE SORRY YOU CANNOT BUY ANYTHING TWICE OKAY!!', 'woocommerce' ), 'error' );
$valid = false;
return $valid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment