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!
In case a customer is logged in, and has purchased a product, the Shop page will not show the “Add to Cart” button, but a “Read more” instead
The single product page, also, won’t show the Add to Cart button at all (once again, in case the current logged in user has purchased that product already)
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”
Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.
If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!
Need Help with WooCommerce?
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
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.
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? Support? Leave your Comment Now! _____
If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. 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 BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)
With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.
Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.
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!