php – Variant Item SKU as Product Code

I am working a new site for my company. We have products with variations. All variations have their own SKU number. When selecting 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 can then be downloaded to our ERP system and all 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 is type variation that the variation SKU becomes the product SKU that 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.

The code that is creating the Hosted Order I believe 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;

I am admittedly a real novice at this so any and all suggestions would be helpful.