Last active
February 12, 2019 10:41
-
-
Save robin-scott/4c8ea6bba196129172d2bd876b637b8a to your computer and use it in GitHub Desktop.
Make woocommerce not allow a product user has purchased before to be purchased again
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
// posted by Robin Scott https://silicondales.com/tutorials/woocommerce-tutorials/woocommerce-tutorial-allow-users-purchase-items/ - 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