How to Hide the Add to Cart Button If Already Purchased in WooCommerce

How to Hide the Add to Cart Button If Already Purchased in WooCommerce
On this page
  1. Why Block Repeat Purchases of the Same Item
  2. Step 1: Filter Purchasability Based on Purchase History
  3. What This Actually Changes
  4. Troubleshooting
  5. Frequently Asked Questions
  6. Conclusion

You can hide the Add to Cart button if already purchased in WooCommerce using the woocommerce_is_purchasable filter combined with wc_customer_bought_product(), which prevents a logged-in customer from buying the same product twice.

Why Block Repeat Purchases of the Same Item

  • One-time licenses, single-use vouchers, or unique digital products shouldn’t be purchasable more than once per customer
  • It prevents accidental duplicate orders for products that logically only need to be bought once
  • It closes the loophole of a customer bypassing a hidden button by adding the product via a direct URL

Step 1: Filter Purchasability Based on Purchase History

PHP
/** Prevent buying a product again once a customer has already purchased it */
add_filter( 'woocommerce_is_purchasable', 'block_repeat_purchase_of_owned_product', 9999, 2 );

function block_repeat_purchase_of_owned_product( $is_purchasable, $product ) {

    if ( wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) {
        $is_purchasable = false;
    }

    return $is_purchasable;
}
Hide the add to cart button if already purchased in WooCommerce: the page before adding the code
Before
Hide the add to cart button if already purchased in WooCommerce: the page after adding the code
After

What This Actually Changes

Once active, the shop page swaps “Add to Cart” for “Read More” on the affected product, the single product page hides the Add to Cart button entirely, and even a direct add-to-cart URL will fail with a “Sorry, this product cannot be purchased” notice.

Troubleshooting

Customers can still add the product via a cached page

Clear any full-page cache after activating this filter, since a stale cached version of the product page may still show the original button to logged-in users.

Guests can still purchase the product repeatedly

This is expected — wc_customer_bought_product() checks purchase history tied to a registered account, so guest checkouts without an account aren’t tracked the same way.

Frequently Asked Questions

Can I customize the message shown when purchase is blocked?

Yes, hook into woocommerce_single_product_summary or a similar template hook to display custom text explaining why the button is hidden, rather than relying on the default WooCommerce message.

Does this apply to variable products correctly?

wc_customer_bought_product() checks against the parent product ID, so purchasing any variation counts as having bought the parent product for this check.

Can I apply this rule to only specific products?

Yes, add a product ID or category check inside the function so the restriction only applies to products meant to be one-time purchases.

Consider pairing this with a short explanatory message near the removed button, since a shopper who doesn’t understand why they can’t repurchase an item they already own may otherwise assume something is broken rather than intentional. A one-line note linking to their existing order or download is usually enough context to avoid a confused support ticket, and it turns a restriction into a helpful shortcut back to what they already bought.

Conclusion

One filter is enough to hide the Add to Cart button if already purchased in WooCommerce, and it closes both the visible button and the direct-URL workaround at the same time.

See also How to Check if a Customer Has Already Purchased a Product in WooCommerce. Then read How to Hide Price and Add to Cart for Logged Out Users in WooCommerce.

Prefer no code? All-in-One Utilities Woo Add-on adds over 50 WooCommerce features, so you can switch them on without code.

Leave a Reply

Schedule a call