Make Products Non-Purchasable

In the previous tutorial I showed you how to hide product prices, now let’s continue with the same idea of transforming a WooCommerce store into a catalog and disable purchasing products. Without plugins.

A small note before all – methods, described in this tutorial don’t remove the “Add to cart” button completely. It will be just transformed into “Read more”.

Products that are not allowed to be purchased

If at the moment of integrating these methods into a website, customers have any of the non-purchasable products in their carts, the products will be immediately removed.

Remove Product Prices or Set the Product Stock to Zero

These works on a per product basis but the good thing is that you do not even have to mess with the code.

Go to any product settings and set its price to 0.

You can product price to zero to prevent the product from being purchased

Another option is to open “Inventory” tab and set the stock status “Out of Stock” or stock quantity to Zero.

WooCommerce product stock management

Ok, as I already mentioned below, it works good on a per product basis, but if you would like to turn your WooCommerce store into a catalog and disable purchasing any product?

woocommerce_is_purchasable

As simple as to insert the below code into your functions.php file, you can completely disable purchasing all the products on your WooCommerce website.

add_filter('woocommerce_is_purchasable', 'misha_catalog_mode_on');
 
function misha_catalog_mode_on( $is_purchasable ) {
 
	$is_purchasable = false;
	return $is_purchasable;
 
}

Actually this filter hook can be written just in a single line of code, but I wanted to keep things clear for you. So, here is how:

add_filter( 'woocommerce_is_purchasable', '__return_false' );

The next thing I want to show you is how you can use woocommerce_is_purchasable filter hook for products in specific product categories or even for products with certain IDs.

Here are the examples:

/*
 * Disable product with ID = 10 from being purchased no matter what
 */
add_filter('woocommerce_is_purchasable', 'misha_catalog_mode_on_for_product', 10, 2 );
 
function misha_catalog_mode_on_for_product( $is_purchasable, $product ) {
 
	if( $product->get_id() == 10 ) { // you can set multiple conditions here
		return false;
	}
 
	return $is_purchasable;
}
/*
 * Disable products from category "Uncategorized" from being purchased no matter what
 */
add_filter('woocommerce_is_purchasable', 'misha_catalog_mode_on_for_category', 10, 2 );
 
function misha_catalog_mode_on_for_category( $is_purchasable, $product ) {
 
	if( has_term( 'uncategorized', 'product_cat', $product->get_id() ) ) {
		return false;
	}
 
	return $is_purchasable;
}

You can find more examples of has_term() usage in this tutorial.

More about turning WooCommerce Store into a Catalog

Misha Rudrastyh

Misha Rudrastyh

I love WordPress, WooCommerce and Gutenberg so much. 10 yrs of experience.

Need some custom developer help? Let me know

Follow Misha

Need some help with WooCommerce?

If you need some professional developer help, I will be happy to assist you.

Contact me Who I am?

Leave a comment

php js HTML CSS Code

I will only use your personal information to contact you. Privacy Policy