Skip to content
Advertisement

Disable add to cart button for an array of products IDs in WooCommerce

In WooCommerce, I’m trying to disable add to cart button for an array of product IDs but I can’t find the problem.

I am trying to use this function:

JavaScript

And this is my check() function code (update):

JavaScript

But this doesn’t work.

What am I doing wrong?

Thanks

Advertisement

Answer

Updated for WooCommerce 3+

Use in_array() instead like:

JavaScript

Where not_purchasable_ids() is the function that returns an array of non purchasable products Ids (here simplified):

JavaScript

This code goes in functions.php file of your active child theme (or active theme). Tested and works.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement