WooCommerce: Hide Hidden Products From Cart, Order, Emails
While working on a workaround for a client, I had to hide a hidden product from the cart, checkout, order received and emails. Hidden products already don’t show on the shop and category pages, but they do show on the cart if they’re added to cart “programmatically”.
A tough task, but as usual here I come with the solution 🙂
You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"
Does this snippet (still) work?
Please let me know in the comments if everything worked 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 on PHP 7.3.
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!
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.
40 thoughts on “WooCommerce: Hide Hidden Products From Cart, Order, Emails”
This code breaks my site.
I don’t have error code.
thanks for your help !
Works for me, must be something else
I’ve been using your snippet for quite some time now, thank you very much for that. 🙂
It seems that the latest Woocommerce update [5.5.1 ] broke this snippet, since the ‘hidden’ products are now visible in both cart & checkout.
Do you know what causes this sudden change?
I don’t think there were major changes in WooCommerce in regard to this. If you revert Woo to a previous version it works? Sure it’s not another plugin or your active theme?
The code breaks my site. It does hide the products in my cart but it breaks the product page. Only one product becomes visible and the layout breaks.
Any ideas how to fix the issue?
Hi Brooke, which PHP error di you get?
whether the product is a downloadable product. can the client still have the linked files to download in the “my downloads” area?
I haven’t tested that case scenario, so let us know
We are randomly seeing the following error regarding this snippet:
PHP Fatal error: Uncaught Error: Call to a member function get_catalog_visibility() on bool in /home/hpadmin/public_html/wp-content/themes/aurum-child/functions.php:1474
We are currently running WP 5.4.2 and WooCommerce 4.2.0
#0 /home/hpadmin/public_html/wp-includes/class-wp-hook.php(287): bbloomer_hide_hidden_product_from_order_woo333(true, Object(WC_Order_Item_Product))
#1 /home/hpadmin/public_html/wp-includes/plugin.php(206): WP_Hook->apply_filters(true, Array)
#2 /home/hpadmin/public_html/wp-content/themes/aurum/woocommerce/order/order-details-item.php(23): apply_filters(‘woocommerce_ord…’, true, Object(WC_Order_Item_Product))
#3 /home/hpadmin/public_html/wp-content/plugins/woocommerce/includes/wc-core-functions.php(251): include(‘/home/hpadmin/p…’)
#4 /home/hpadmin/public_html/wp-content/themes/aurum/woocommerce/order/order-details.php(63): wc_get_template(‘order/order-det…’, Array)
#5 /home/hpadmin/public_html/wp-content/plugins/woocommerce/includes/wc-core-functions.php(251): include(‘/home/hpadmin/p…’)
#6 /home/hpadmin/public_html/wp-content/plugins/wo in /home/hpadmin/public_html/wp-content/themes/aurum-child/functions.php on line 1474
Any insights or thoughts on what would cause this?
Weird. Try adding this check:
June 2nd, 2020 – Code is still working. However, the hidden product is still visable in the email that is send to the client (woocommerce/templates/emails/customer-processing-order.php). How can I fix this?
Hi Wim, just tested on latest Woo, works perfectly, emails included. Must be something else
Can i remove the hidden product from the admin order edit page?
Varun, 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’ve added your snippet. Seems to work except for emails… They’re still being sent out after I programmatically do the transaction.
How can I disable emails from going to customer?
Hi Andy, this hides products from emails, but does not disable emails though
This code still works. But I would like to also remove so it’s not counted in the items in cart at the top. Maby its just my theme that shows the number of items. Is there any solution for that. The product is a membership that should be seen that they get. It’s for a lifetime discount.
Not working 3/1/2020. Hidden product is hidden as is entire cart content.
Please advise. Latest wordpress release
Hi, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?
To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.
Hope this helps!
Hi, thanks a lot for this code!
However, the mini cart on top right seems not to update correctly in my case.
Should it work for the mini cart as well?
I dont talk about lowering the item count, just hiding the items in mini cart.
Hello Meena, correct, this snippet does not work with the mini cart. You need to add another hook trigger for hook = “woocommerce_widget_cart_item_visible” for that. Hope this helps
Nice code, but i dont want to hide any product since am using [product_page id ="8080"] to display specific product on the front end, however i want to allow users to purchase this product but i dont want it listed in the orders section in my account orders page, i want only to hide some specific ordered Products from showing on the my orders page.
hi Chris, 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!
This works great! Thank you so much.
I need one thing to make this complete. Currently, hidden products show up in the menu cart number indicator.
Would you please help me hide hidden products from this number indicator? I need this number indicator for my store.
Hey Chad: https://businessbloomer.com/woocommerce-exclude-hidden-products-from-mini-cart-counter/
Just an FYI – Be aware of this code!
We added it to our site and it caused all new orders to duplicate 4-5 times and customers got charged for every duplicated order. A nightmare!
We love this site and all the snippets are great and never had an issue until now.
It could just be a conflict on our end, but just be ware.
Thanks Miguel 🙂 This snippet does not duplicate orders, so yes this is definitely another sort of conflict. Always test snippets on a development/clone website and never on a live environment. Thank you!
In th latest version of woocommerce, there seems to be an issue with the following code:
The order doesn’t go through to the success/thank you page, email notification is not sent to the customer/admin. Does the code hide the HIDDEN products on order email as well?
Unable to verify as the code is not triggering the successful order email.
You’re absolutely right Vinoth 🙂 Snippet has now been updated!
I thank you for this HOOK, which has been very useful for me.
Now, how could I hide just the prices of the order?
Hola Yeorsh, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
This is not working on WooCommerce 3.0.7, any ideas on what needs to be updated for it to work?
I’ve written some custom jQuery to remove or hide the items in Cart and on Order Received screens on the front-end, but of course this doesn’t stop the hidden product from showing up on customer emails and elsewhere as needed.
Ethan, thanks so much for your comment! And yes, you’re right 🙂 Snippet has now been updated – test it out!
I have added this code to my child theme functions.php file but hidden products still show in cart and emails. Is this code still valid for current wordpress and woo commerce versions. Thank you
Hey Rory, thanks for your comment! Yes, it should definitely work 🙂 Can you send me a screenshot of your hidden product “edit page” and also cart and email? Thank you!
Thanks for the quick reply. I did figure out a mistake I had made which blocked this from working. Now resolved. Thank you so much for making this tutorial and supporting your page.
I do have another question. I noticed when I generate invoices the hidden products show up again only on the invoice. Should this code be blocking that as well? Do you know of additional code to also hide from invoice?
Excellent Rory 🙂 Do you use a particular invoice plugin, or are you referring to the default WooCommerce invoice?
I have been using booster.io for its pdf feature and the pdf invoice is what includes the hidden items.
Hey Rory, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R