Error in class-dibs-post-checkout.php on line 131 and 133
-
When I cancel an order I get this error:
[09-Jun-2021 21:39:11 UTC] PHP Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, stdClass given in /public_html/wp-content/plugins/dibs-easy-for-woocommerce/classes/class-dibs-post-checkout.php:131 Stack trace: #0 /public_html/wp-includes/class-wp-hook.php(294): DIBS_Post_Checkout->dibs_order_canceled() #1 /public_html/wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters()`
There is two errors, on line 131 and 131. Here are the entire code-chunk:
$request = new DIBS_Requests_Cancel_Order( $order_id ); $request = json_decode( $request->request() ); // COMMENT: Returns an object!! $wc_order = wc_get_order( $order_id ); if ( null === $request ) { $wc_order->add_order_note( sprintf( __( 'Order has been canceled in Nets', 'dibs-easy-for-woocommerce' ) ) ); } else { if ( array_key_exists( 'errors', $request ) ) { // COMMENT: should be isset instead of array_key_exists. It's an object, not an array. $message = wp_json_encode( $request->errors ); } elseif ( array_key_exists( 'message', $request ) ) { // COMMENT: should be isset instead of array_key_exists. It's an object, not an array. $message = wp_json_encode( $request->message ); } else { $message = wp_json_encode( $request ); } /* Translators: Nets message. */ $wc_order->add_order_note( sprintf( __( 'There was a problem canceling the order in Nets: %s', 'dibs-easy-for-woocommerce' ), $message ) ); }
I’ve added comments above.
In short, then
array_key_exists( 'message', $request )
should be replaced withisset( $request->message )
.
- The topic ‘Error in class-dibs-post-checkout.php on line 131 and 133’ is closed to new replies.