Disable cart rule based on rule id when category matches

Disable cart rule based on rule id when category matches



function woo_discount_rules_disable_specific_cart_rule_when_cart_item_has_specific_category($status, $rule){
    $rule_id = 230;//ENTER RULE ID
    if($rule->ID == $rule_id){
        $categories = array(16,17);//ADD CATEGORY FOR WHICH YOU DOESN'T REQUIRED DISCOUNT.
        foreach(wc()->cart->cart_contents as $cart){
            $product = $cart['data'];
            $product_category_ids = $product->get_category_ids();
            if(!empty($product_category_ids) && is_array($product_category_ids)){
		$result_array = array_intersect($categories, $product_category_ids);
                if(count($result_array)){
                    $status = false;
                    break;
                }
            }
        }
    }

    return $status;
}
add_filter('woo_discount_rules_run_cart_rule', 'woo_discount_rules_disable_specific_cart_rule_when_cart_item_has_specific_category', 10, 2);