Now, let’s say you’re out of stock for certain products, so you want to temporarily hide the Add to Cart button for those products.
To remove the button for specific products, copy and paste this script into the functions.php file of the child theme:
/* REMOVE ADD TO CART BUTTON ON SPECIFIC PRODUCT IDs*/
add_filter(‘woocommerce_is_purchasable’, ‘filter_is_purchasable’, 10, 2);
function filter_is_purchasable($is_purchasable, $product ) {
global $product;
if( in_array( $product->get_id(), not_purchasable_ids() )) {
return false;
}
return $is_purchasable;
}
function not_purchasable_ids() {
return array( 624,625 );
}
n this example scenario, we disable the Add to Cart button for products with IDs 624 and 625. To adapt it to your WooCommerce store, simply replace these IDs with your product IDs. As you can see, you can add multiple products by simply separating the identifiers with a comma.