After that, however, I realized that the “woocommerce_is_purchasable” filter offered by the WooCommerce plugin makes the task much easier than just combining the two mini-plugins above.
So, here’s how it’s done – enjoy!
PHP Snippet: Deny Further Sales If User Has Already Purchased a Product @ Shop / Single Product Page
This snippet will:
Hide the Add to Cart completely on the single product page
Rename the Add to Cart on the Shop Page to “Read More”
This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101
Related content
WooCommerce: Custom Add to Cart URLs – The Ultimate Guide In WooCommerce you can add a product to the cart via a custom link. You just need to use the “add-to-cart” URL parameter followed by the product ID. This tutorial will show you how to create custom URLs to add simple, variable and grouped products to the cart – as well as defining the add […]
WooCommerce Visual Hook Guide: Single Product Page Here’s a visual hook guide for the WooCommerce Single Product Page. This is part of my “Visual Hook Guide Series“, through which you can find WooCommerce hooks quickly and easily by seeing their actual locations (and you can copy/paste). If you like this guide and it’s helpful to you, let me know in the comments! […]
WooCommerce: Disable Variable Product Price Range $$$-$$$ You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
WooCommerce: Hide Price & Add to Cart for Logged Out Users You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
WooCommerce Visual Hook Guide: Archive / Shop / Cat Pages I’ve created a visual HTML hook guide for the WooCommerce Archive Page (which is the same page for the Shop, Category, Tag pages). This visual guide belongs to my “Visual Hook Guide Series“, that I’ve put together so that you can find WooCommerce hooks quickly and easily by seeing their actual locations (and you can […]
Rodolfo Melogli
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli
16 thoughts on “WooCommerce: Hide Add to Cart If Already Purchased”
Sandra Stark
I am finally using your code as a way to hide the cart, but I was wondering it there is any way to change the default cart message to a custom message instead of “PRODUCT NAME has been removed from your cart because it can no longer be purchased. Please contact us if you need assistance.” The message may generate lots of emails to me. I thought it was worth asking. I currently have just a message appear when logged in has already purchased within the shop view (your code as a base).
Hi,
I have used below code for one time product purchase, code is working fine, but I want to exclude wallet (Product ID 1417) from this code. Please suggest me, how to exclude wallet from this code.
Hello Franster, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
I’m looking for a way to completely hide a purchased product for logged in users. I’m adding around 300 subscriptions to my site with Woo Commerce Subscriptions and it would be great if my customer who has 200 of them will only see the 100 that are left. Not in the store, but to be able to specify it in a grid/masonry. In my world this is essential and something they missed in Subscriptions, but also core. Any ideas??!?
Hi Patrik thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Could this easily be extended to variable products? I’d love it if I could hide “add to cart” on a variable product upon purchase of certain attributes and eliminate all variations upon a purchase of a different attribute.
Hi James thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Fabian, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Questions? Feedback? Customization? Leave your comment now! _____
If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!
I am finally using your code as a way to hide the cart, but I was wondering it there is any way to change the default cart message to a custom message instead of “PRODUCT NAME has been removed from your cart because it can no longer be purchased. Please contact us if you need assistance.” The message may generate lots of emails to me. I thought it was worth asking. I currently have just a message appear when logged in has already purchased within the shop view (your code as a base).
Hi Sandra, there is a filter indeed:
You can basically print whatever you like by setting your own custom $message
Hope this helps
Hi,
I have used below code for one time product purchase, code is working fine, but I want to exclude wallet (Product ID 1417) from this code. Please suggest me, how to exclude wallet from this code.
Hi Anoop! Try with
How to exclude multiple product ID?
Hello Franster, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi,
I’m looking for a way to completely hide a purchased product for logged in users. I’m adding around 300 subscriptions to my site with Woo Commerce Subscriptions and it would be great if my customer who has 200 of them will only see the 100 that are left. Not in the store, but to be able to specify it in a grid/masonry. In my world this is essential and something they missed in Subscriptions, but also core. Any ideas??!?
Hi Patrik thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Could this easily be extended to variable products? I’d love it if I could hide “add to cart” on a variable product upon purchase of certain attributes and eliminate all variations upon a purchase of a different attribute.
Hi James thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Thanks for the tips these are invaluable.. How do we tweak it only for a certain product category?
Hey Mac, I suggest you take a look at “conditional logic”: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Enjoy ๐
How can we replace it with view cart?
Hi Fabian, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Rodolfo, you are the best!
Thank you Gino!