Original query:

WITH conditions AS (
    SELECT location_intspace, location_id 
    FROM
        (SELECT UNNEST(STRING_TO_ARRAY('758,759', ',')) AS location_intspace) a
    CROSS JOIN
        (SELECT UNNEST(STRING_TO_ARRAY('1,2,3,4,5,1511,940,931,660,661', ',')) AS location_id) b
)
SELECT DISTINCT ON (product_id) product_id, price, is_instock
FROM conditions
INNER JOIN LATERAL(
                   SELECT price, is_instock, product_id
                   FROM products_displayproductaccess_755
                   WHERE location_id = conditions.location_id::int AND location_intspace = conditions.location_intspace::int 
                   ORDER BY price DESC, is_instock DESC, product_id LIMIT 100
                   ) as L on true
LIMIT 100