I'm using this API to create orders in WooCommerce: https://github.com/kloon/WooCommerce-REST-API-Client-Library
When I'm adding an order:
$orderData = array(
"order" => array(
"line_items" => array(
array(
"product_id" => 1,
"quantity" => 1
)
)
)
);
$client->orders->create($orderData);
everything works fine, the order is created in WooCommerce.
But When I want to add a product variation with meta data about the variation, how should I do that?
I tried several things, including:
$orderData = array(
"order" => array(
"line_items" => array(
array(
"product_id" => 1,
"quantity" => 1,
"variation_id" => 2,
"variations" => array(
"color" => "black"
)
)
)
)
);
$client->orders->create($orderData);
What I want to achieve is, when getting the order with:
$client->orders->get( $order_id );
The color info is already added to the meta data of the line item (so the color description is visible in the order details when sending an email):
line_items: [
{
id: ...,
subtotal: "...",
subtotal_tax: "...",
total: "...",
total_tax: "...",
price: "...",
quantity: 1,
tax_class: null,
name: "Product name",
product_id: 1,
sku: "",
meta: [
{
key: "color",
label: "Color",
value: "black"
}
]
}
]
Hope the question is clear enough and someone can point me to the right solution :)
Thanks for your patience to read this.