Merge pull request #17320 from woocommerce/fix/17308-remove-item-reloads-unsaved-items
Deleting order items, save unsaved items first
This commit is contained in:
commit
aaf69124b3
|
@ -549,6 +549,10 @@ jQuery( function ( $ ) {
|
|||
action : 'woocommerce_remove_order_item',
|
||||
security : woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
// Check if items have changed, if so pass them through so we can save them before deleting.
|
||||
if ( 'true' === $( 'button.cancel-action' ).attr( 'data-reload' ) ) {
|
||||
data.items = $( 'table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]' ).serialize();
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
|
@ -556,7 +560,7 @@ jQuery( function ( $ ) {
|
|||
type: 'POST',
|
||||
success: function( response ) {
|
||||
if ( response.success ) {
|
||||
$( '#woocommerce-order-items' ).find( '.inside' ).empty();
|
||||
$( '#woocommerce-order-items' ).find( '.inside' ).empty();
|
||||
$( '#woocommerce-order-items' ).find( '.inside' ).append( response.data.html );
|
||||
wc_meta_boxes_order.init_tiptip();
|
||||
wc_meta_boxes_order_items.unblock();
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -985,11 +985,20 @@ class WC_AJAX {
|
|||
try {
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$order_item_ids = $_POST['order_item_ids'];
|
||||
$items = ( ! empty( $_POST['items'] ) ) ? $_POST['items'] : '';
|
||||
|
||||
if ( ! is_array( $order_item_ids ) && is_numeric( $order_item_ids ) ) {
|
||||
$order_item_ids = array( $order_item_ids );
|
||||
}
|
||||
|
||||
// If we passed through items it means we need to save first before deleting.
|
||||
if ( ! empty( $items ) ) {
|
||||
$save_items = array();
|
||||
parse_str( $items, $save_items );
|
||||
// Save order items
|
||||
wc_save_order_items( $order_id, $save_items );
|
||||
}
|
||||
|
||||
if ( sizeof( $order_item_ids ) > 0 ) {
|
||||
foreach ( $order_item_ids as $id ) {
|
||||
wc_delete_order_item( absint( $id ) );
|
||||
|
|
Loading…
Reference in New Issue