WC_AJAX::save_order_items()
Save order items via ajax.
Description Description
Source Source
File: includes/class-wc-ajax.php
public static function save_order_items() {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) || ! isset( $_POST['order_id'], $_POST['items'] ) ) {
wp_die( -1 );
}
if ( isset( $_POST['order_id'], $_POST['items'] ) ) {
$order_id = absint( $_POST['order_id'] );
// Parse the jQuery serialized items.
$items = array();
parse_str( wp_unslash( $_POST['items'] ), $items ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
// Save order items.
wc_save_order_items( $order_id, $items );
// Return HTML items.
$order = wc_get_order( $order_id );
// Get HTML to return.
ob_start();
include 'admin/meta-boxes/views/html-order-items.php';
$items_html = ob_get_clean();
ob_start();
$notes = wc_get_order_notes( array( 'order_id' => $order_id ) );
include 'admin/meta-boxes/views/html-order-notes.php';
$notes_html = ob_get_clean();
wp_send_json_success(
array(
'html' => $items_html,
'notes_html' => $notes_html,
)
);
}
wp_die();
}