skip to Main Content

How can I modify the code bellow to include multiple product ids ?

add_filter('woocommerce_is_purchasable', 'my_woocommerce_is_purchasable', 10, 2);
function my_woocommerce_is_purchasable($is_purchasable, $product) {
    return ($product->id == 100 ? false : $is_purchasable);
}

Thanks

2

Answers


  1. Maybe something like this:

    function my_woocommerce_is_purchasable( $is_purchasable, $product ) {
        $prod = [ 100, 101, 102 ];
        return ( in_array( $product->id, $prod ) ? false : $is_purchasable);
    }
    
    Login or Signup to reply.
  2. Try this:

    add_filter('woocommerce_is_purchasable', 'my_woocommerce_is_purchasable', 10, 2);
    function my_woocommerce_is_purchasable($is_purchasable, $product) {
        
        $product_ids = array(100, 200, 300);
    
        return ( in_array( $product->id, $product_ids ) ? false : $is_purchasable);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search