Running a WooCommerce online store? Obviously, you want that your customers can easily add your products to their shopping cart, isn’t it? Then why would you want to hide the ‘Add to Cart’ button in WooCommerce? Let us first understand why this need might arise and then learn how to go about it.
There are plenty of instances when you would want to hide the WooCommerce ‘Add to Cart’ button. Here are a few of them:
- You are using WooCommerce simply as an online catalog of products, not for making sales.
- The displayed product is not yet available in the market.
- The displayed product is presently out of stock.
- The product is only available for sale for select customers (for example, those registered on the WooCommerce store).
- The WooCommerce ‘Add to Cart’ button is not working due to some technical problem.
Now that we have listed the reasons, let’s discuss why a simple Google search will not provide the answer to the question – “How do you hide the ‘Add to Cart’ button on WooCommerce?”
Search Results can guide you – but not always in the right direction
Try searching for the keywords, “remove add to cart button WooCommerce” on Google – and you will find a couple of credible search results. Most of these search results will guide you to remove the following functions using the “Remove Action” function:
However, doing this will disable the ‘Add to Cart’ button on your WooCommerce website entirely (on all pages). The first action above effectively disables the “Add to Cart” button on a particular product page, while the second action implements the same outcome on the shop page.
Another major problem with this action is that besides hiding the “Add to Cart” button, it can also remove some WooCommerce template files, which is unnecessary. We would recommend that before reusing this “Remove Action” code, first understand what each line of code does – and then go ahead if required.
Instead of using this function, there are far simpler and safer ways on WooCommerce to hide the ‘Add to Cart’ button. Let’s discuss them in the following sections.
Hiding the ‘Add to Cart’ button in WooCommerce – the RIGHT way!!
Here is how you can hide the ‘Add to Cart’ button the right way for each of the following cases:
- To remove ‘Add to Cart’ for a single unpurchaseable product For the selected product, open the “simple.php” file (from the single-product/add-to-cart folder) and set the “is_purchaseable” Boolean variable to “False”. This action will disable the “Cart” button and replace it with the “Read more…” button.
- To disable the ‘Add to Cart’ button for specific products You can choose to hide the “Add to Cart” button for specific products (or product pages).To do this, you can simply remove the price figure for the product, which will also remove the “Add to Cart” button. Another option is to set the product stock level to zero, thus automatically disabling the Cart button.Alternatively, you can open the “functions.php” file (from the “theme” folder) and add a filter to disable the “purchaseable” attribute for a specific product ID.
- To hide ‘Add to Cart’ for users who have not signed in You can choose to hide the “Add to Cart” button for users who have not logged in (or registered) on your WooCommerce store. This is typically used when you want to run a special offer (or offer product discounts) for only your registered (and signed in) users.To do this, you can open the “functions.php” file (from the “theme” folder) and set the “is_purchaseable” variable to “True” only for users who have logged in.
- To remove ‘Add to Cart’ for users based on their user roleYou can choose to completely remove the “Add to Cart” button based on the user role. For example, you can remove the “Cart” button for all users with administrative rights.To do this, from the “functions.php” file (in the “theme” folder), you can use the “get_user_role” function to retrieve the user role and set the “is_purchaseable” variable to “False” for users with administrator role.
- To disable ‘Add to Cart’ for selected product categories. Another option is to disable the “Add to Cart” button for select product categories (for example, laptops).To do this, you can open the “functions.php” file (from the “theme” folder) and check the product category using the “is_product_category” function. For the selected product category, you can use the “remove_action” function to configure disabling the “Cart” button.
- To disable ‘Add to Cart’ for a selected date range.You can also choose to disable the “Add to Cart” button temporarily for a new product for a selected date range. For example, you may be having a new product launch on a certain date. In this case, you can disable the “Cart” button until the date of the product launch and enable it on the launch date.To do this, you can open the “functions.php” file (from the “theme” folder) and use the “$current_date” and “$release_date” variables to obtain the current and release dates, respectively. You can then set the “is_purchaseable” variable to “False” for the following conditions:
- The current date is less than the release date.
- A product with specific product ID.
This action will also replace the “Cart” button with the “Read more…” button till the product release date.
As discussed, there are multiple cases where you need to hide, remove, or disable the “Add to Cart” button on your WooCommerce store. To create a positive shopping experience for your customers, you can further customize your “Add to Cart” button in many ways.
With its expertise in WooCommerce development, Flipper Code can provide a wide variety of services to help you build a great website. Our dedicated and highly experienced WordPress team has been doing coding and plugin development since the year 2012. Here is an informative blog on how to implement WooCommerce shipping based on zip code.
We can help in developing an entire WordPress website or even performing major bug fixes. Register today on the Flipper Code website or drop us a message with your name and email address.