Make wc_add_order_item pass correct values to woocommerce_new_order_item

Fixes #14362
This commit is contained in:
Mike Jolley 2017-04-17 12:50:27 +01:00
parent 0d849139f9
commit 887cb8b62c
1 changed files with 9 additions and 8 deletions

View File

@ -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 );