Important note: I am not using functions.php for any cart functionality. I am using standalone php files, it has to stay this way.
In Woocommerce, I'm creating a cart dynamically adding a product using:
global $woocommerce;
$cart = $woocommerce->cart;
//set the custom item data
$item_data = array();
$product_id = '121';
$item_data = array(
'plain_data' => 'test data',
'array_data' => array('URL' => 'URL', 'Signals' => 'SIGNALS')
);
//Add it to the cart
$cart->add_to_cart($product_id, 1, null, null, $item_data);
Then I create the order from the cart using:
global $woocommerce;
$cart = $woocommerce->cart;
$order_data = array('payment_method' => 'PayPal');
$checkout = $woocommerce->checkout();
$order_id = $checkout->create_order($order_data);
But the custom item data that I added does not get saved in the order.
What am I doing wrong?