Automattic\WooCommerce\Blocks\Domain\Services
DraftOrders::assert_order_results() private WC 1.0
Asserts whether incoming order results are expected given the query this service class executes.
{} It's a method of the class: DraftOrders{}
No Hooks.
Return
Null. Nothing.
Usage
// private - for code of main (parent) class only $result = $this->assert_order_results( $order_results, $expected_batch_size );
- $order_results(WC_Order[]) (required)
- The order results being asserted.
- $expected_batch_size(int) (required)
- The expected batch size for the results.
Code of DraftOrders::assert_order_results() DraftOrders::assert order results WC 5.0.0
private function assert_order_results( $order_results, $expected_batch_size ) {
// if not an array, then just return because it won't get handled
// anyways.
if ( ! is_array( $order_results ) ) {
return;
}
$suffix = ' This is an indicator that something is filtering WooCommerce or WordPress queries and modifying the query parameters.';
// if count is greater than our expected batch size, then that's a problem.
if ( count( $order_results ) > 20 ) {
throw new Exception( 'There are an unexpected number of results returned from the query.' . $suffix );
}
// if any of the returned orders are not draft (or not a WC_Order), then that's a problem.
foreach ( $order_results as $order ) {
if ( ! ( $order instanceof WC_Order ) ) {
throw new Exception( 'The returned results contain a value that is not a WC_Order.' . $suffix );
}
if ( ! $order->has_status( self::STATUS ) ) {
throw new Exception( 'The results contain an order that is not a `wc-checkout-draft` status in the results.' . $suffix );
}
}
}