Bookmark

No account yet? Register

Difficulty: Easy

Sometimes you want to make some of your products in you WooCommerce store not purchasable. Instead you want your customers to contact you in order to buy them. In this article we will show you how to accomplish that. It is very simple and it will require you to get the product Id you wish not to make purchasable and modify/insert some code in functions.php

TLDR SECTION

TLDR
File: Functions.php

add_filter('woocommerce_is_purchasable', 'woowiki_my_woocommerce_is_purchasable', 10, 2);
function woowiki_my_woocommerce_is_purchasable($is_purchasable, $product) {
		$product_id = array(<pruduct_id>,<pruduct_id>);
		foreach($product_id as $id){
			if($product->id==$id){
				return false;
			}else{
				return true;
			}
		}      
}

*Don’t forget to replace <pruduct_id> with the ID of a product you want to make not purchaseable

Finding Product Id

To find product ID of a WooCommerce product you want to make not purchasable you need to navigate to product list using admin interface. There should be a menu where it says Products

After navigating there you will see a window like this one below. In there you just need to find the product you want to make not purchasable and hover above it. Underneath it’s title product ID will show up. Remember that product id or even better write it down somewhere.

Now that you have written down or remembered the product ID of products you want to make not purchasable. You need to navigate to your functions.php file.

Making products not purchasable

Customizing functions.php file in WordPress

Go to the admin interface and then go to Appearance and then under Appearance select Theme Editor

After navigating there you will see a windows like this one below. In there select Theme Functions (functions.php) and then at the end of the file put this code. Where it says <pruduct_id> insert your product IDs. If you have only one product that line of code will look something like this:
$product_id = array(14781);

If you have multiple products taht you neeed to make not purchaseable that line of code will look similar to this:
$product_id = array(14781,14251,1432,14783);

add_filter('woocommerce_is_purchasable', 'woowiki_my_woocommerce_is_purchasable', 10, 2);
function woowiki_my_woocommerce_is_purchasable($is_purchasable, $product) {
		$product_id = array(<pruduct_id>,<pruduct_id>);
		foreach($product_id as $id){
			if($product->id==$id){
				return false;
			}else{
				return true;
			}
		}      
}

Write A Comment