WooCommerce woocommerce_new_order_item hook

I am using the woocommerce_new_order_item hook in my functions.php file.

The code I have is:

Read More
add_action( 'woocommerce_new_order_item', 'wc_order_item_added',  1, 1  );
function wc_order_item_added($item_id, $item, $order_id) {
    global $mysqli;

    //$order = new WC_Order( $item_id );

    $sql = $mysqli->query("INSERT into a_test (one) values ('".$item_id."');");
}

Which I found from: http://hookr.io/actions/woocommerce_new_order_item/

But the $order_id variable is not being returned. The only variable that is working is, $item_id

Related posts

Leave a Reply

1 comment

  1. Change the action to this

    add_action( 'woocommerce_new_order_item', 'wc_order_item_added',  1, 3 );
    

    The last parameter is number of variables that the callback accepts