Website Building » WooCommerce » How Do I Disable Add to Cart Button in WooCommerce?

How Do I Disable Add to Cart Button in WooCommerce?

Last updated on January 19, 2023 @ 1:59 pm

If you’re running a WooCommerce store, there may come a time when you need to disable the “Add to Cart” button for certain products. Maybe you’re selling an item that’s out of stock and don’t want customers to order it, or maybe you want to discourage impulse buys by making people think twice before adding something to their cart. Whatever the reason, disabling the Add to Cart button is easy to do with just a few lines of code.

The first thing you’ll need to do is find the product ID of the item you want to disable the Add to Cart button for. You can find this in the URL when you’re editing the product in WooCommerce. For example, if the URL is yourstore.com/wp-admin/post.php?post=123&action=edit, then the product ID is 123.

Once you have the product ID, open up your code editor and add the following code snippet to your child theme’s functions.php file:

function disable_add_to_cart( $url ) {
	if ( ! is_admin() && is_main_query() ) {
		global $post;
		if ( $post->ID == 123 ) { // Replace 123 with your product ID
			$url = ''; // Disable Add to Cart button
		}
	}
	return $url; 
} 
add_filter( 'woocommerce_product_add_to_cart_url', 'disable_add_to_cart' );

You can add this code snippet to your site using a plugin like Code Snippets, or if you’re comfortable with code, you can add it directly to your child theme’s functions.php file.

And that’s it! You’ve now successfully disabled the Add to Cart button for a specific product on your WooCommerce store.

PRO TIP: If you are considering disabling the add to cart button in WooCommerce, be aware that this could have unintended consequences. For example, if you have a sale going on and people are trying to add items to their cart, they may get frustrated and leave your site without completing their purchase. Additionally, if you have products that are out of stock, disabling the add to cart button will prevent people from being able to backorder them.
Kathy McFarland

Kathy McFarland

Devops woman in trade, tech explorer and problem navigator.