Woocommerce - limit a product to only be purchased once per user

Hi there,

Does anyone know how I can limit a product to only be purchased once per user account? Is there any plugin I can use to achieve this?

My site is all digital downloads and it has a chart for sales, I need this function to stop people purchasing the product many times to effect the charts.

Many thanks in advance

I don’t know of any through CodeCanyon sadly. Most plugins like this are one time limitations, meaning they only check the cart, not a user’s history. I had to use one once and I found it through PNW Design. I don’t think I can include links, but if you do a google search you should be able to find some ranging from reasonable to quite expensive.

There is a notification plugin through CodeCanyon that tells the customer they have already purchased the item, but I don’t think it will prevent them from doing it again.

Thanks bolderelements :slight_smile: I did already try PNWs plugin, brought it yesterday, but it doesn’t work for me for some frustrating reason!.

Hi!

Did you manage to find a solution for this?
I am trying to achieve the same thing.

You can try to achive this by hire a freelancer to do, here’s my opinion:

  • When user check out > write the user ID into a custom field for that product > save

  • When user try to “add_to_cart”, we will perform an action, check if the user id is in the field we wrote > true > show notice bought cant bought again, else put it on the user’s cart.

It’s pretty simple though, you can hire someone on Upwork for that.

comfythemes said

You can try to achive this by hire a freelancer to do, here’s my opinion:

  • When user check out > write the user ID into a custom field for that product > save

  • When user try to “add_to_cart”, we will perform an action, check if the user id is in the field we wrote > true > show notice bought cant bought again, else put it on the user’s cart.

It’s pretty simple though, you can hire someone on Upwork for that.

I would do something similar, but I would not pollute the post meta for that. It’s already possible to find out which products a user bought by querying the orders. Also, no need to wait until a customer adds the product to the cart, such operation can be prevented altogether.

// Disable repeat purchase of products / variations
function sv_disable_repeat_purchase( $purchasable, $product ) {

// Don't run on parents of variations,
// this will already check variations separately
if ( $product->is_type( 'variable' ) ) {
    return $purchasable;
}

// Get the ID for the current product (passed in)
$product_id = $product->is_type( 'variation' ) ? $product->variation_id : $product->id; 

// return false if the customer has bought the product / variation
if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product_id ) ) {
    $purchasable = false;
}

// Double-check for variations: if parent is not purchasable, then variation is not
if ( $purchasable && $product->is_type( 'variation' ) ) {
        $purchasable = $product->parent->is_purchasable();
}

return $purchasable;

}
add_filter( ‘woocommerce_is_purchasable’, ‘sv_disable_repeat_purchase’, 10, 2 );