function Amz_FBA_Check_If_Orders_Need_Tracking()
{
    global $wpdb;
    $args = array('meta_key' => 'FBA_Tracking_ID', 'meta_value' => 'Waiting', 'post_type' => 'shop_order');
    $OrderArray = get_posts($args);
    foreach ($OrderArray as $SingleOrder) {
        $ID = $SingleOrder->ID;
        GetAmzFBAOrderTracking($ID);
    }
    $OrderCount = count($OrderArray);
    if ($OrderCount == 0) {
        AmzFBA_Woo_Log("Neutral", "Order", "Order Tracking Update", "No orders currently awaiting tracking information.");
    }
}
function MarkOrderAsComplete($order, $order_id)
{
    $level = "Neutral";
    $category = "Order";
    $title = "Order completion";
    AmzFBA_Woo_Log($level, $category, $title, "Marking the order as complete : " . $order->get_order_number() . " " . $order_id);
    # $order = new WC_Order($order_id);
    $order->update_status('completed');
    /*
    global $woocommerce;
    $mailer = $woocommerce->mailer();
    $orderCompleteEmail = $mailer->emails['WC_Email_Customer_Completed_Order'];
    AmzFBA_Woo_Log($level, $category, $title, "Enabled : " . $orderCompleteEmail->is_Enabled());
    
    $level = "Neutral";
    $category = "Order";
    $title = "Order complete email";
    AmzFBA_Woo_Log($level, $category, $title, "Enabled : " . $orderCompleteEmail->is_Enabled() . ", Order id: " . $order->get_order_number());
    $orderCompleteEmail->trigger($order_id);
    
    #if ($orderCompleteEmail->is_Enabled()) {
    #    $orderCompleteEmail->trigger($order_id);
    #}
    AmzFBA_Woo_Log($level, $category, $title, "Marking the order as complete : " . $order->get_order_number());
    */
}
function invokeGetPackageTrackingDetails(FBAOutboundServiceMWS_Interface $service, $request)
{
    try {
        $response = $service->getPackageTrackingDetails($request);
        if ($response->isSetGetPackageTrackingDetailsResult()) {
            $getPackageTrackingDetailsResult = $response->getGetPackageTrackingDetailsResult();
            if ($getPackageTrackingDetailsResult->isSetTrackingNumber()) {
                $TrackingNumber = $getPackageTrackingDetailsResult->getTrackingNumber();
                update_post_meta($order_id, "FBA_Carrier_Tracking_Code", $TrackingNumber);
            }
            if ($getPackageTrackingDetailsResult->isSetCarrierCode()) {
                $DeliveryCompany = $getPackageTrackingDetailsResult->getCarrierCode();
                update_post_meta($order_id, "FBA_Carrier", $DeliveryCompany);
            }
            if ($getPackageTrackingDetailsResult->isSetCarrierPhoneNumber()) {
                $CarrierPhoneNumber = $getPackageTrackingDetailsResult->getCarrierPhoneNumber();
                update_post_meta($order_id, "FBA_Carrier_Phone_Number", $CarrierPhoneNumber);
            }
            if ($getPackageTrackingDetailsResult->isSetCarrierURL()) {
                $CarrierURL = $getPackageTrackingDetailsResult->getCarrierURL();
                update_post_meta($order_id, "FBA_Carrier_URL", $CarrierURL);
            }
        }
    } catch (FBAOutboundServiceMWS_Exception $ex) {
        // echo("XML: " . $ex->getXML() . "\n");
        $level = "Bad";
        $category = "Order";
        $title = "Get Tracking Error - Order ID:" . $order_id;
        $info = "Caught Exception: " . $ex->getMessage() . " | Response Status Code: " . $ex->getStatusCode() . " | Error Code: " . $ex->getErrorCode() . " | Error Type: " . $ex->getErrorType() . " | Request ID: " . $ex->getRequestId();
        AmzFBA_Woo_Log($level, $category, $title, $info);
    }
}