diff --git a/includes/api/class-wc-rest-order-refunds-controller.php b/includes/api/class-wc-rest-order-refunds-controller.php index 7a43d9ab504..8f23f2fa7eb 100644 --- a/includes/api/class-wc-rest-order-refunds-controller.php +++ b/includes/api/class-wc-rest-order-refunds-controller.php @@ -282,9 +282,15 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller { 'line_items' => $request['line_items'], 'refund_payment' => is_bool( $request['api_refund'] ) ? $request['api_refund'] : true, 'restock_items' => true, - 'meta_data' => empty( $request['meta_data'] ) ? null : $request['meta_data'], ) ); + if(!empty( $request['meta_data'] ) && is_array( $request['meta_data'] )) { + foreach ( $request['meta_data'] as $meta ) { + $refund->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); + } + $refund->save_meta_data(); + } + if ( is_wp_error( $refund ) ) { return new WP_Error( 'woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500 ); } diff --git a/includes/wc-order-functions.php b/includes/wc-order-functions.php index cc23815a599..1f75eda82a8 100644 --- a/includes/wc-order-functions.php +++ b/includes/wc-order-functions.php @@ -475,7 +475,6 @@ function wc_create_refund( $args = array() ) { 'line_items' => array(), 'refund_payment' => false, 'restock_items' => false, - 'meta_data' => array(), ); try { @@ -499,10 +498,6 @@ function wc_create_refund( $args = array() ) { $refund->set_parent_id( absint( $args['order_id'] ) ); $refund->set_refunded_by( get_current_user_id() ? get_current_user_id() : 1 ); - foreach ( $args['meta_data'] as $meta ) { - $refund->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); - } - if ( ! is_null( $args['reason'] ) ) { $refund->set_reason( $args['reason'] ); }