I am working on a new website for my company. We have products with variations. each variation have its own SKU number. When we select the product, the correct item is displayed in the cart with the correct SKU (the one assigned to the variation).
I'm using another plugin that creates Hosted Orders for me that then can be downloaded to our ERP system and all of that works fine except for one thing. The SKU that is getting passed to the Hosted Order is the parent item SKU and not the variant.
I need a way to determine if the product has variations and the variation SKU becomes the product SKU which is picked up by the other plugin. I've tried an if/else
function in the new plugin but it didn't change the result.
I believe the code that is creating the Hosted Order is this code snippet.
$items = $this->order->get_items();
// Line items can be added to a Transaction individually or as an array
$lineItems = array();
$itemcount = 0;
foreach($items as $item_id => $item_data) {
array_push($lineItems, new ConnectLineItem);
$product = wc_get_product($item_data['product_id']);
$lineItems[$itemcount]->ProductCode = $product->get_sku();
$lineItems[$itemcount]->Category = "";
$lineItems[$itemcount]->Description = substr($item_data['name'], 0, 50);
$lineItems[$itemcount]->Quantity = $item_data['quantity'];
$lineItems[$itemcount]->UnitOfMeasure = "PCE";
$lineItems[$itemcount]->LineAmount = $item_data['total'];
$lineItems[$itemcount]->UnitPrice = $item_data['total'] / $item_data['quantity'];
$lineItems[$itemcount]->LineTaxAmount = $item_data['subtotal_tax'];
$lineItems[$itemcount]->LineDiscountAmount = "0.00";
$itemcount = $itemcount + 1;
}
$trans->addLineItemArray($lineItems);
I am admittedly a real novice at this so any and all suggestions would be helpful.