Calculate discount from sale price for specific products (when set calculate discount from regular p

Calculate discounts from the sale price for specific products (when set to calculate discounts from the regular price).

if (!function_exists('awdr_calculate_from_sale_price')) {
    function awdr_calculate_from_sale_price($product_price, $product, $quantity, $cart_item, $calculate_discount_from)
    {
        $exclude_products_ids = [18];    //enter product ids here
        if (is_object($product) && method_exists($product, 'get_id')) {
            $product_id = $product->get_id();
            if (in_array($product_id, $exclude_products_ids)) {
                $product_price = $product->get_price();
            }
        }
        return $product_price;
    }

    add_filter('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', 'awdr_calculate_from_sale_price', 100, 5);
    add_filter('advanced_woo_discount_rules_product_price_on_before_calculate_discount', 'awdr_calculate_from_sale_price', 100, 5);
}