Merge pull request #14447 from woocommerce/fix/14362

Make wc_add_order_item pass correct values to woocommerce_new_order_item
This commit is contained in:
Claudio Sanches 2017-04-17 12:54:40 -03:00 committed by GitHub
commit 04f61c73dc
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 );