Fix Issue #16663. Moved meta creation to `prepare_object_for_database`.

This commit is contained in:
james 2017-08-31 18:17:14 +01:00
parent ce39e3aaa8
commit 1820c6a99d
2 changed files with 7 additions and 6 deletions

View File

@ -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 );
}

View File

@ -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'] );
}