WooCommerce disable add to cart for certain products with 2 easy ways

disable add-to-cart button for products banner
Table of Contents

In WooCommerce, the add-to-cart button is a crucial element that allows customers to purchase products directly from your online store. However, there are scenarios where you need to disable add to cart for certain products in WooCommerce, such as:

  • Out-of-Stock Products: You may want to hide the add-to-cart button for products that are temporarily out of stock but still visible in your store.
  • Inquiry-Only Products: For products that require a custom quote or inquiry before purchase, you might want to disable the add-to-cart button.
  • Display-Only Products: If you’re showcasing products that are not available for direct purchase (e.g., upcoming items or special collections), hiding the button can prevent confusion.
  • Membership or Restricted Products: For products available only to specific user roles or members, you may want to hide the button for non-eligible customers.

By hiding or disabling the add-to-cart button for certain products in WooCommerce, you can create a more tailored shopping experience for your customers and better manage your store’s functionality.

There are two main methods to hide or disable the add-to-cart button for specific products in WooCommerce:

In this guide, we’ll walk you through both methods, ensuring you can easily implement the solution that best suits your needs. Whether you’re a developer or a store owner, you’ll find these steps straightforward and effective. Let’s dive in!

What is WooCommerce hide add to cart?

Hiding the add-to-cart button in WooCommerce for certain products means completely removing the button from the product page without displaying any replacement message or alternative option. When implemented, customers visiting the product page will not see the add-to-cart button at all, and no additional text or elements will take its place.

This approach is useful for scenarios where you want to restrict purchasing options for specific products, such as display-only items, out-of-stock products, or items available only for inquiry while maintaining a clean and uncluttered product page.

What is WooCommerce disable add to cart?

WooCommerce disabling add to cart allows store owners to replace the button with a custom message that is not linked to the cart or checkout process. This means customers will see a tailored message, such as “Contact Us for Pricing” or “Available for Inquiry,” instead of the standard add-to-cart button. 

The custom message is purely informational and does not redirect users to the cart or enable them to purchase the product directly. Although it may guide customers to other useful web pages like Registration or Contact Us pages.

This approach is ideal for products that require special handling, such as custom orders, out-of-stock items, or products available only through consultation, providing a clear and professional way to communicate with customers without enabling direct purchases.

How to disable add to cart for certain products in WooCommerce?

Let’s review a step-by-step guide for the above mentioned methods.

Method 1: Hide and disable add-to-cart button programmatically

To disable the add-to-cart button for specific products in WooCommerce using custom code, you can add a PHP snippet to your theme’s functions.php file. This method allows you to target specific products by their IDs, categories, or other criteria.

What to Consider Before Inserting the Code?

  • Backup Your Site: Always create a full backup of your website, including the database and files, before making any changes to the code.
  • Use a Child Theme: If you’re adding the code to your theme’s functions.php file, use a child theme to ensure your changes are not overwritten during theme updates.
  • Get Product IDs: Ensure you have the correct product IDs for the products you want to target. You can find the product ID by navigating to WordPress Dashboard > Products > All Products.

Hover over the product for which you want to hide the add-to-cart button and note down the product ID (in this example, the ID is 25).

Woocommerce products id
  • Ask expert or use third party plugin: If you have no experience in coding, ask an expert to insert the custom code or use a plugin like Code Snippet to do it correctly.

By following these considerations, you can safely and effectively disable the add-to-cart button for specific products in WooCommerce using custom code.

Hide the Add to Cart Button for all products. 

Use the following code, if you want to hide add to cart button from both the product detail page and the shop page:

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');

Once inserting the code, you should see that the add-to-cart button has been removed from all products.

Hide add-to-cart button by code

Hide add to cart button for specific product

To hide the add-to-cart button for a specific product in WooCommerce, add the following code to your functions.php file:

add_action( 'WooCommerce_after_shop_loop_item', 'hide_add_to_cart_for_specific_product', 10 );
function hide_add_to_cart_for_specific_product() {
      global $product;
    if ( 25 == $product->get_id() ) {
          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 );
    }
}
Hide add-to-cart button on specific products result

By applying this code, the add-to-cart button will be removed for the product with ID 25. You can replace this ID (Yellow highlighted) with any other product IDs to disable their add to cart button.

Read More: WooCommerce hide add to cart button for specific category (3 ways).

Disable add to cart button for certain productsΒ 

Add the following code to disable the add-to-cart button for a specific product in WooCommerce:

add_filter( 'WooCommerce_is_purchasable', 'disable_add_to_cart_button' );
function disable_add_to_cart_button( $is_purchasable ) {
//add conditions here to disable the button for specific products if needed

Return false; // return false disables the 'Add to Cart' button
}

By running this code, customers are not able to click on the add to cart button and add items to their cart.

Method 2: WooCommerce disable add to cart for certain products with hide price and add-to-cart button plugin

Using the WooCommerce hide price and add-to-cart button plugin is a simple and effective way to disable the add-to-cart button for specific products without needing to write any code.Β 

This plugin is a powerful tool designed to enhance the flexibility of WooCommerce stores by allowing merchants to hide product prices or add to cart button from specific users or user roles. 

The plugin offers customizable options, such as hiding prices globally, for specific products, or particular user roles, and it can replace the price or add to cart label with a custom message like “Login to See Price” or “Contact Us for Pricing.” Additionally, it integrates seamlessly with WooCommerce, ensuring compatibility with most themes and plugins. 

This functionality helps businesses maintain pricing confidentiality while improving user experience and encouraging customer engagement.

Below is a step-by-step guide on how to use this plugin to achieve your goal:

Step 1: Install and activate the plugin

  • Download the ZIP file and get the License key.
  • Go to your WordPress Dashboard> Plugins > Add New.
  • Click on the Upload button and choose the ZIP file. 
  • Press Install to see the below items in the WordPress Dashboard. 
Opening ithemeland's license page
  • Go to the IThemeland > License. 
  • Insert the License key in the form and activate the plugin.
Activating woo hide price plugin

Step 2: Add a rule to hide the add-to-cart button for specific products

After activating the plugin, go to IThemeland > Hide Price in your WordPress dashboard.

Opening hide price plugin for woo
  • Click on the Add Rule button on the Rules page to open the New Rule form.
Add rule in hide price plugin

In the new rule form, you need to fill in the following fields:

  1. Title: Add a title for your new rule.
  2. Apply rule to: In this section, you need to add one of the following:
    • Specific User roles: Choose one or more user roles that you have already defined in WordPress to apply the rule on. For example, customers, managers, contributors, etc.
    • Specific Customers: Add the name of one or more customers that you want to hide add-to-cart button for them.
    • Guests: Choose this option if you want to hide the add to cart button from the guest users.
  3. In the Select Products fields, add one or more products to apply the changes only to those specific products.

Note: You can alternatively mark Apply on All products to hide the add-to-cart button of all products in your store.

Set new rule fore hide hide price and add-to-cart button
  1.  Mark Hide Add to Cart button. If you just mark this option and save changes, the add to cart button will completely disappear from the product page of those specific products.

However, you can add a custom message instead of the add-to-cart button in the Custom button label field.

It is also possible to add a URL to the Custom button link to guide the customers to that address when clicking on the add-to-cart button.

Example 1: Hide the add-to-cart button for specific products from guests users

Suppose that you want to hide the add to cart button for Red wine, Tiramisu, and Luxury biscuits for guests in your store. 

To do this, you just need to:

  • Write a title like β€œWooCommerce disable add to cart for certain products”.
  • Choose Guest from the list of Apply rule to field.
  • Add the mentioned products to the Select Products field.
  • Mark Hide add to cart button.
  • Press the Add Rule button.
Hide add-to-cart button for specific products and guest users

So, when guests visit your website, the add to cart button won’t display them for the selected products:

Resut of hide add-to-cart button-using hide price plugin
WooCommerce hide price and add-to-cart by user role

Example 2: Disable add-to-cart button for specific products for customers  

In this example, we tried to disable the add to cart button and display a Contact Us message to the customers when they visit the same products as in the previous example.

  • Write a name like β€œDisable add to cart button”.
  • Choose a Specific user role, then, Customer from the list of Apply rule to and Rule for user roles fields, respectively.
  • Add the same products in the Select Products field.
  • Mark Hide Add to cart button .
  • Write Contact us in the Custom button label.
  • Press the Add rule button.
Rule for disabling add-to-cart button for customer users

So, when customers visit the selected product pages, they will see the Contact Us message instead of the add to cart button. They can not click on the button and proceed to checkout because you have disabled it:

Result of showing custom button instead of add-to-car

Why do you need to disable the add-to-cart button for specific products?

Disabling the add-to-cart button is a strategic decision that serves various business and operational purposes. Here are some common reasons why store owners might need WooCommerce disable add-to-cart button for specific products:

Products available for inquiry only

Some products, such as custom-made items, bulk orders, or high-value goods, may require direct communication with the seller before purchase. Disabling the add-to-cart button and replacing it with a message like β€œContact Us for Pricing” encourages customers to reach out for more details.

Out-of-Stock products

If a product is temporarily out of stock but you still want to display it on your store, hiding the add-to-cart button prevents customer frustration and avoids misleading them into thinking the product is available for immediate purchase.

Display-only or upcoming products

For products that are showcased as part of a catalog or upcoming collection but not yet available for purchase, hiding the button ensures customers understand the product is not ready for sale.

Membership or restricted products

If certain products are exclusive to specific user roles (e.g., wholesale customers or members), WooCommerce disable add-to-cart button for non-eligible users ensures only authorized customers can purchase them.

Prevent Direct Purchases

Some products may require additional steps before purchase, such as signing a contract, providing documentation, or attending a consultation. Hiding the button ensures customers follow the correct process.

Promotional or informational products

Products used for promotional purposes (e.g., free gifts or demo items) or informational purposes (e.g., product bundles or guides) may not be available for direct purchase. Hiding the button avoids confusion.

Compliance with Regulations

 In some industries, certain products may require age verification, legal agreements, or other compliance measures before purchase. Hiding the button ensures customers follow the necessary steps.

Enhance User Experience

By hiding the add-to-cart button for specific products, you can create a cleaner and more focused shopping experience, guiding customers toward the products they can actually purchase.

Conclusion

In summary, hiding the add-to-cart button for certain products helps store owners manage their inventory, improve customer communication, and create a more tailored shopping experience. It ensures customers are not misled and aligns with your business goals and operational requirements.