- Check input (no 'id', has 'code') and throw an error if needed
before removing the existing coupons, so an invalid input
won't cause the loss of these existing coupons.
- Also, check that the coupon is actually valid as part of the
input check.
- Cache the coupon objects that are created during the input check,
and apply them directly.
- Don't check if 'coupon_lines' is an array and contains arrays,
that's already done by the REST API engine by looking at the schema.
- Adjust unit tests.
This commit revert some of the changes added in #27735 because wc_get_products and wc_get_orders is not fully compitable with API controller queries. Since we are close to release 4.9, its better to revert and fix them properly then rush a fix. This undones some the performance improvements we acheived in 27735, in favor of more stability, hopefully we will be able to restore this soon.