Website Building » WooCommerce » How Do I Get Rid of the Add to Cart Button in WooCommerce?

How Do I Get Rid of the Add to Cart Button in WooCommerce?

Last updated on January 20, 2023 @ 12:03 pm

If you’re running a WooCommerce store, you might want to remove the “Add to Cart” button on certain products. For example, you might be selling an event ticket where people need to register first, or a service that can’t be purchased online. In this article, we’ll show you how to remove the Add to Cart button in WooCommerce.

There are two ways to remove the Add to Cart button in WooCommerce. You can either do it with a plugin or with code. We’ll show you both methods so that you can choose the one that’s best for you.

Method 1: Remove the Add to Cart Button in WooCommerce with a Plugin

The easiest way to remove the Add to Cart button in WooCommerce is with a plugin. We recommend using the Hide Add to Cart and Prices plugin. It’s free and it works with all WooCommerce themes.

Once you’ve installed and activated the plugin, go to WooCommerce > Settings > Products > Pricing. From here, you can select which user roles will be able to see prices and add to cart buttons. For most sites, we recommend hiding these elements for everyone except for administrators.

If you want to take things a step further, the plugin also lets you hide prices and the Add to Cart button on specific products. To do this, edit the product and scroll down to the “Hide Product Data” section. From here, you can select which data is hidden on the product page.

Method 2: Remove the Add to Cart Button in WooCommerce with Code

If you’re comfortable working with code, then you can also remove the Add to Cart button in WooCommerce by editing your theme files. First, you’ll need to create a child theme so that your changes aren’t overwritten when your main theme is updated.

Once you’ve created your child theme, edit the “functions.php” file and add the following code:

<?php
function remove_add_to_cart_buttons() {
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 ); }
add_action( 'init', 'remove_add_to_cart_buttons' );?>

This code will remove all “Add to Cart” buttons from your store. If you only want to remove these buttons from certain products, then you’ll need to edit the code slightly.

PRO TIP: If you are using WooCommerce to sell products on your WordPress site, you may want to remove the “Add to Cart” button on certain pages. For example, you might want to disable the button on the product page if the product is out of stock. Or, you may want to remove it from the shop page if you only want customers to purchase products through your single product pages. Removing the “Add to Cart” button can be done with a few lines of code.
<?php
function conditionally_remove() {
global $product;
 
if ( $product->get_id() == 2 ) { 
// Change 2 with your product ID
 
remove action( 'WooCommerce simple product summary', 
   'WooCommerce template single addtocart', 30 ); 
} 
} 
add action( 'init', 'conditionallyRemoveButtons' ); ?>

In this case, we’re removing the Add To Cart button from a product with an ID of 2. You’ll need to change this number to match the ID of your product.

<?php function wcstoretest(){ 
   global $product; if($product->getId()==1){
//replace 1 by id of any other product for which you want to 
hide addtocart button 
 
return true;}} addfilter('WooCommerce simple product summary',
   'wcstor test');?>

You can find your product’s ID by going to “WooCommerce > Products”. Then hover over your product and look at the URL in your browser’s address bar.

Conclusion:

In this article, we showed you how yo can easily remove the “Add to cart” button in WooComerce using a plugin or with code.

Kathy McFarland

Kathy McFarland

Devops woman in trade, tech explorer and problem navigator.