From 887cb8b62ca4b9f90125fe3bab5db60f27821f01 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 17 Apr 2017 12:50:27 +0100 Subject: [PATCH] Make wc_add_order_item pass correct values to woocommerce_new_order_item Fixes #14362 --- includes/wc-order-item-functions.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/includes/wc-order-item-functions.php b/includes/wc-order-item-functions.php index a325c311d58..9989d8f90e7 100644 --- a/includes/wc-order-item-functions.php +++ b/includes/wc-order-item-functions.php @@ -15,23 +15,24 @@ if ( ! defined( 'ABSPATH' ) ) { /** * Add a item to an order (for example a line item). * - * @access public * @param int $order_id - * @return mixed + * @param array $item_array + * @return int|bool Item ID or false */ function wc_add_order_item( $order_id, $item ) { - if ( ! $order_id = absint( $order_id ) ) + if ( ! $order_id = absint( $order_id ) ) { return false; + } $defaults = array( - 'order_item_name' => '', - 'order_item_type' => 'line_item', + 'order_item_name' => '', + 'order_item_type' => 'line_item', ); - $item = wp_parse_args( $item, $defaults ); - + $item_array = wp_parse_args( $item_array, $defaults ); $data_store = WC_Data_Store::load( 'order-item' ); - $item_id = $data_store->add_order_item( $order_id, $item ); + $item_id = $data_store->add_order_item( $order_id, $item_array ); + $item = WC_Order_Factory::get_order_item( $item_id ); do_action( 'woocommerce_new_order_item', $item_id, $item, $order_id );