From 1596979d757f9ab107b6865a1b77e30a3dfb162b Mon Sep 17 00:00:00 2001 From: Manos Psychogyiopoulos Date: Tue, 22 Aug 2017 15:19:20 +0300 Subject: [PATCH] Reload order items on add --- assets/js/admin/meta-boxes-order.js | 10 ++++++---- .../meta-boxes/views/html-order-items.php | 1 + includes/class-wc-ajax.php | 19 +++++++++++-------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/assets/js/admin/meta-boxes-order.js b/assets/js/admin/meta-boxes-order.js index e18837e3886..9c98574ac0a 100644 --- a/assets/js/admin/meta-boxes-order.js +++ b/assets/js/admin/meta-boxes-order.js @@ -1095,17 +1095,19 @@ jQuery( function ( $ ) { item_to_add: add_item_ids, dataType : 'json', order_id : woocommerce_admin_meta_boxes.post_id, - security : woocommerce_admin_meta_boxes.order_item_nonce + security : woocommerce_admin_meta_boxes.order_item_nonce, + data : $( '#wc-backbone-modal-dialog form' ).serialize() }; $.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) { if ( response.success ) { - $( 'table.woocommerce_order_items tbody#order_line_items' ).append( response.data.html ); + $( '#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.stupidtable.init(); } else { window.alert( response.data.error ); } - - wc_meta_boxes_order.init_tiptip(); wc_meta_boxes_order_items.unblock(); }); } diff --git a/includes/admin/meta-boxes/views/html-order-items.php b/includes/admin/meta-boxes/views/html-order-items.php index 121c6cee6c4..d8c1f5a5be3 100644 --- a/includes/admin/meta-boxes/views/html-order-items.php +++ b/includes/admin/meta-boxes/views/html-order-items.php @@ -56,6 +56,7 @@ if ( wc_tax_enabled() ) { foreach ( $line_items as $item_id => $item ) { do_action( 'woocommerce_before_order_item_' . $item->get_type() . '_html', $item_id, $item, $order ); + $class = isset( $new_item_ids ) && is_array( $new_item_ids ) && in_array( $item_id, $new_item_ids ) ? 'new_row' : ''; include( 'html-order-item.php' ); do_action( 'woocommerce_order_item_' . $item->get_type() . '_html', $item_id, $item, $order ); diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index acf1f4f3085..c0a7cc1e57d 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -770,26 +770,29 @@ 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'] ) ); + $new_item_ids = array(); if ( ! $order ) { throw new Exception( __( 'Invalid order', 'woocommerce' ) ); } - ob_start(); - foreach ( $items_to_add as $item_to_add ) { if ( ! in_array( get_post_type( $item_to_add ), array( 'product', 'product_variation' ) ) ) { continue; } - $item_id = $order->add_product( wc_get_product( $item_to_add ) ); - $item = apply_filters( 'woocommerce_ajax_order_item', $order->get_item( $item_id ), $item_id ); - $order_taxes = $order->get_taxes(); - $class = 'new_row'; + $item_id = $order->add_product( wc_get_product( $item_to_add ) ); + $item = apply_filters( 'woocommerce_ajax_order_item', $order->get_item( $item_id ), $item_id ); + $new_item_ids[] = $item_id; - do_action( 'woocommerce_ajax_add_order_item_meta', $item_id, $item ); - include( 'admin/meta-boxes/views/html-order-item.php' ); + do_action( 'woocommerce_ajax_add_order_item_meta', $item_id, $item, $order ); } + do_action( 'woocommerce_ajax_added_order_items', $item_id, $item, $order ); + + $data = get_post_meta( $order_id ); + + ob_start(); + include( 'admin/meta-boxes/views/html-order-items.php' ); wp_send_json_success( array( 'html' => ob_get_clean(), ) );