Restrict WooCommerce Product Purchase to One Time

Restrict Product Purchase to One Time in WooCommerce

If you want to allow customers to buy a WooCommerce product only once, you can use custom PHP code to stop users from placing repeat orders for that product.

Why Limit to One Purchase?

This feature is useful for exclusive products like memberships, one-time downloads, or limited-time offers. It avoids confusion and duplicate purchases.

How to Block Repeat Purchases

You can use WooCommerce hooks and functions like wc_customer_bought_product and woocommerce_is_purchasable to prevent repeat buys.

Step 1: Add Code to functions.php

Insert this code in your theme’s functions.php file:

function custom_restrict_duplicate_product_purchase($purchasable, $product_id, $user_id) {
    if (is_user_logged_in()) {
        if (wc_customer_bought_product('', $user_id, $product_id)) {
            $purchasable = false;
        }
    }
    return $purchasable;
}
add_filter('woocommerce_is_purchasable', 'custom_restrict_duplicate_product_purchase', 10, 3);
Step 2: Test It

Log in as a user who already purchased the product. When viewing the same product again, the “Add to Cart” button will be disabled.

What This Does

  • Checks if the user is logged in.
  • Validates if they’ve bought the product before.
  • Disables purchasing again if true.

Limitations

This won’t stop guest users or users with a new account. You’ll need additional validation or a plugin to handle those cases.

Advanced Control

Want to block repeat orders across accounts or for guest users? Use a plugin like “WooCommerce Purchase Restrictions” or create a more advanced custom rule.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.