Return array when getting wc orders

This commit is contained in:
dinamiko 2022-09-14 10:39:15 +02:00
parent 1396520c57
commit 82418a071a
2 changed files with 16 additions and 17 deletions

View file

@ -78,22 +78,20 @@ class CheckoutPaymentApprovalReversed implements RequestHandler {
return $this->no_wc_orders_from_custom_ids( $request, $response );
}
if ( is_array( $wc_orders ) ) {
foreach ( $wc_orders as $wc_order ) {
if ( in_array( $wc_order->get_status(), array( 'pending', 'on-hold' ), true ) ) {
$error_message = sprintf(
// translators: %1$s is the order id.
__(
'Failed to capture order %1$s through PayPal.',
'woocommerce-paypal-payments'
),
(string) $wc_order->get_id()
);
foreach ( $wc_orders as $wc_order ) {
if ( in_array( $wc_order->get_status(), array( 'pending', 'on-hold' ), true ) ) {
$error_message = sprintf(
// translators: %1$s is the order id.
__(
'Failed to capture order %1$s through PayPal.',
'woocommerce-paypal-payments'
),
(string) $wc_order->get_id()
);
$this->logger->warning( 'CHECKOUT.PAYMENT-APPROVAL.REVERSED received. ' . $error_message );
$this->logger->warning( 'CHECKOUT.PAYMENT-APPROVAL.REVERSED received. ' . $error_message );
$wc_order->update_status( 'failed', $error_message );
}
$wc_order->update_status( 'failed', $error_message );
}
}

View file

@ -42,9 +42,9 @@ trait RequestHandlerTrait {
* Get WC orders from the given custom ids.
*
* @param array $custom_ids The custom ids.
* @return stdClass|WC_Order[]
* @return WC_Order[]
*/
protected function get_wc_orders_from_custom_ids( array $custom_ids ) {
protected function get_wc_orders_from_custom_ids( array $custom_ids ): array {
$order_ids = array_map(
array(
$this,
@ -57,7 +57,8 @@ trait RequestHandlerTrait {
'limit' => -1,
);
return wc_get_orders( $args );
$orders = wc_get_orders( $args );
return is_array( $orders ) ? $orders : array();
}
/**