This commit is contained in:
parent
f0b240d33a
commit
1e66cedaf0
|
@ -1115,6 +1115,11 @@ jQuery( function ( $ ) {
|
|||
data : $( '#wc-backbone-modal-dialog form' ).serialize()
|
||||
};
|
||||
|
||||
// Check if items have changed, if so pass them through so we can save them before adding a new item.
|
||||
if ( 'true' === $( 'button.cancel-action' ).attr( 'data-reload' ) ) {
|
||||
data.items = $( 'table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]' ).serialize();
|
||||
}
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
if ( response.success ) {
|
||||
$( '#woocommerce-order-items' ).find( '.inside' ).empty();
|
||||
|
|
|
@ -773,11 +773,20 @@ class WC_AJAX {
|
|||
$order_id = absint( $_POST['order_id'] );
|
||||
$order = wc_get_order( $order_id );
|
||||
$items_to_add = wp_parse_id_list( is_array( $_POST['item_to_add'] ) ? $_POST['item_to_add'] : array( $_POST['item_to_add'] ) );
|
||||
$items = ( ! empty( $_POST['items'] ) ) ? $_POST['items'] : '';
|
||||
|
||||
if ( ! $order ) {
|
||||
throw new Exception( __( 'Invalid order', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
// If we passed through items it means we need to save first before adding a new one.
|
||||
if ( ! empty( $items ) ) {
|
||||
$save_items = array();
|
||||
parse_str( $items, $save_items );
|
||||
// Save order items.
|
||||
wc_save_order_items( $order->get_id(), $save_items );
|
||||
}
|
||||
|
||||
foreach ( $items_to_add as $item_to_add ) {
|
||||
if ( ! in_array( get_post_type( $item_to_add ), array( 'product', 'product_variation' ) ) ) {
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue