WooCommerce Make Products Non-Purchasable For A Specific Category

WooCommerce category without add to cart button


There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

This snippet allows you to make all products from a specific category non-purchasable. This means the user is unable to buy the product. The ‘add to cart’ button is removed and the ability to add products to the cart is disabled via add to cart URLs.

 * Snippet Name:	WooCommerce Make Products Non-Purchasable For A Specific Category
 * Snippet Author:	ecommercehints.com

add_filter('woocommerce_is_purchasable', 'ecommercehints_catalog_mode_for_specific_category', 10, 2 );

function ecommercehints_catalog_mode_for_specific_category( $is_purchasable, $product ) {
	if (has_term('accessories', 'product_cat', $product->get_id())) { // Change 'accessories' to the category slug you would like non-purchasable
		return false;
	return $is_purchasable;

Snippet Benefits

  • Only allow customers to buy products from a specific category.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

2 Responses

  1. What is “10, 2” in above snippet? If you are mentioning the category number, then you have mentioned category name also other than category number.

    So, if I have to remove add to cart button from my 02 categories (I have total 3 main categories), then what would be the correct snippet for me?

    Thanks in advance.

    1. Hey Juned,
      :: 10 is the Priority. Think of this as the order in which the functions associated with a particular filter are executed. If you used the “woocommerce_is_purchasable” filter hook again, you might want the new function running later so would give it a higher priority number.
      :: 2 is the number of variables the function accepts ($is_purchasable and $product).
      More detail here: https://developer.wordpress.org/reference/functions/add_filter/

      Take a look at line 9 in the code to make the code work for specific categories.


Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

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

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers