ThemeIM Blog Details

How to Remove Add to Cart Button from WooCommerce (No Plugins Required)

How to remove add to cart button from WooCommerce

WooCommerce is the most authentic tool for an eCommerce website. It offers the necessary elements required for an online shop. But you may want to hide or remove some elements depending on the time and situation. The “Add to cart” button might be one of them.

Deleting or hiding the “Add to cart” button can be done in various ways. In this article, we will show you how to remove or hide the “Add to cart” button in several ways.  — But first, you need to know the reasons for removing or hiding this button.

The reasons for removing the “Add to cart” button in WooCommerce?

First, let us explain why you might want to hide the “Add to cart” button. Removing the “Add to cart” button is one of the best ways to close the checkout for a particular store or product. Although this sounds counterintuitive, in some cases it is useful to remove the “Add to cart” button.

— In addition to other options for customizing your store, you may also want to remove the “Add to cart” button for a variety of reasons. Here are some of them –

  • When the “Add to cart” button needs to serve a different purpose (i.e. sending a message to users or booking a schedule for an interview) rather than the default WooCommerce procedure.
  • When a particular product runs out of stock and you don’t want the buyers getting involved in confusion.
  • When a particular product will be soon arriving but is not available for purchase yet.
  • It is better to remove or hide the “Add to cart” button when you are using WooCommerce as a catalog.
  • When you want to set logic conditions or give permission to specific users. For instance, you may want to hide or remove the “Add to cart” button for the non-logged-in users.

The above reasons are very strong, but there can be many other reasons that you want to remove or hide the “Add to cart” button. Now let’s see how to remove the WooCommerce Add To Cart button from your store.

How to remove the “Add to cart” button from WooCommerce

We will show several ways to hide the “Add to cart” button. Each of these ways can be applicable for various situations. Before we start, we want you to look at the processes that we are going to explain –

  • Remove or hide the button for the entire website
  • Hide the remove the button for users who are not logged in or registered
  • Hide or remove the button based on logic conditions
  • Hide or remove the button for a specific product
  • Remove the “Add to Cart” button temporarily for a certain period of time
  • Hide or remove the button with the help of a plugin

Remove or hide the “Add to Cart” button from anywhere on the website:

There are multiple ways to completely hide the “Add to Cart” button in your store. One of the easiest ways is to use the following script in the functions.php file of the child theme:
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

Using the remove_action () hook, we will disable the “Add to Cart” button on the product page first, then we will do the same thing on the store page.

But a cleaner and more reliable solution are to disable the option to buy products. This will make the products unavailable for purchase and prevent users from adding them to the shopping cart.
add_filter( 'woocommerce_is_purchasable', '__return_false');

This filter won’t remove the “Add to Cart” button, but it will be replaced with a “Read More” button. As a result, users will be redirected to the product description page where there is no button.

Note:

Remember, your customers can’t buy products if you keep the “Add to Cart” button disabled. You are doing this knowing this fact. So, it is better to use the add_filter hook rather than the remove_action().

Remove or hide the “Add to cart” button for non-logged-in users

You may not want to show discounts to the users who haven’t logged into your website. Or you may run a special website where products are only available for purchase for the registered users. In such cases, hiding the “Add to cart” button is really important.

Add the following lines inside the functions.php file –

/* REMOVE ADD TO CART BUTTON FOR NON-LOGGED-IN USERS */

if (!is_user_logged_in()) {

// in product page

add_filter('woocommerce_is_purchasable', '__return_false');
}

We have used the is_user_logged_in() WordPress function for keeping the “Add to cart” button hidden or removed from the non-logged-in users.

Remove Add to cart button based on logic conditions

Logic condition applies based on user roles. We need to apply a script from the admin panel. The script handles 2 conditions. The first condition checks if the user has a particular role or not. The second condition keeps the products unpurchasable until the user logs in.

The following code will hide the button for an admin, you can edit it according to the role of the user

/* REMOVE ADD TO CART BUTTON FOR ADMIN USERS */

add_action('wp_loaded','get_user_role');

function get_user_role(){

$current_user = wp_get_current_user();

if(count($current_user->roles)!==0){

if($current_user->roles[0]=='administrator'){

add_filter('woocommerce_is_purchasable', '__return_false');
}
}

Remove Add to cart button for a specific product

Let’s say a specific category of product is stocked out. So, you want to temporarily hide the “Add to cart” button so that your buyers can’t make a purchase until the new stock arrives. It is possible to do that in such a scenario.

First, you need to know the ID of the product that you want to hide. You need to go to the following directory from your WordPress dashboard and hove the mouse on the product that you want to hide –

WordPress dashboard > WooCommerce > Products

WordPress dashboard

Once you find the product ID, you need to add the following code in the functions.php file –
/* REMOVE ADD TO CART BUTTON ON SPECIFIC PRODUCT IDs*/

/add_filter('woocommerce_is_purchasable', 'filter_is_purchasable', 10, 2);

function filter_is_purchasable($is_purchasable, $product ) {

global $product;

if( in_array( $product->get_id(), not_purchasable_ids() )) {

return false;

}

return $is_purchasable;

}

function not_purchasable_ids() {

return array( 624,625 );

}

You can also add multiple product IDs in the code if you want to hide more than one product.

Remove Add to cart for a certain period of time

This is more innovative and creative at the same time. This method is for the advanced user who wants to display the upcoming products for promotions but keeps the “Add to cart” button hidden until the products finally arrive.

Let’s say we want to keep the “Add to cart” button hidden for September 15th, 2021. Because the upcoming products will arrive on that particular date. But we want to show those products on the website for promotion –
add_filter( 'woocommerce_is_purchasable', 'hide_add_to_cart_button_until_date', 10, 2 );

function hide_add_to_cart_button_until_date( $is_purchasable = true, $product ) {

$current_date = date('Y-m-d');

$release_date = date( 'Y-m-d', strtotime('2021-09-15') );

if( strtotime($current_date) < strtotime($release_date) && $product->get_id() == 624 ) {

$is_purchasable = false;

}

return $is_purchasable;

The above script will show a Read more button instead of Add to cart until the date of arrival. It compares the present date with the launch date. If the present date is earlier than the launch date, there will be no “Add to cart” button.

Don’t forget to specify the id of the product for which you want to hide the button.

Remove add to cart button from WooCommerce via a plugin

There are many plugins for removing the “Add to cart” button. This can save you from the hassle of inserting code. Removing Add to cart using plugins is easier for the non-technical person. A plugin named MMWD Remove Add To Cart for WooCommerce is well recommended.

MMWD

This plugin uses the woocommerce_is_purchasable filter instead of the Add to cart action to delete all the associated buttons on the WooCommerce website. It doesn’t affect other actions associated with it. The plug-in also provides the function for deleting product prices and single product pages.

Be noted – removal price may not work for themes that do not use standard WooCommerce hooks.

Summing Up

In this tutorial, you learned about different ways to remove the “Add to Cart” button. We have shown you how to hide it for your entire website, for specific products, users, logic conditions, and even how to hide it and automatically show it again after a specific time. This gives you the flexibility to adapt your store to different situations.

— Just use the above methods and their scripts as a basis and edit them to get the most out of your business. If you don’t want to remove the “Add to Cart” button, it’s completely fine. All in all, hiding the Add to Cart button is useful in many different situations.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.