<?php
/**
* Template Name: Track Order Status
*/
?>
<?php
 $order_id = $_GET["o"];
// $order_id = 5689; //MNP
// $order_id = 5682; //Call Courier
// $order_id = 5051; //Swyft Logistcs
// $order_id = 5655; //VCS
// $order_id = 5793; //Processing
// $order_id = 5749; //Cancelled
// $order_id = 2854; //Completed
// $order_id = 3424; // refunded
// $order_id = 5565; // delivered
// $order_id = 5747; // Shipped
	
if ( (isset($order_id)) and (get_post_type($order_id ) == "shop_order") ){
		$order = new WC_Order( $order_id );
		$order_status = $order->get_status();
		//echo "<hr >";
		$shipment_tracking_items = get_post_meta( $order_id, '_wc_shipment_tracking_items', true );
		$cc =  $shipment_tracking_items[0]["tracking_provider"];
		//echo "<hr >";
		$track_id = $shipment_tracking_items[0]["tracking_number"];
		//echo "<hr >";
		$tracking_url = get_field($cc.'_tracking_url', 'option');
		//echo "<hr />";
	
		if ($cc == "mp" and ($order_status == "processing" or $order_status == "shipped" or $order_status == "delivered" or $order_status == "completed") ){?>

			<form name="trackcn" id="trackcn" action="<?php echo $tracking_url; ?>" method="POST">
				<input type="hidden" id="cn" name="cn" required="" value="<?php echo $track_id;?>">
			</form>
			<script>document.getElementById("trackcn").submit();</script>

		<?php }elseif ($cc == "callcourier" and ($order_status == "processing" or $order_status == "shipped" or $order_status == "delivered" or $order_status == "completed")){
			// echo "CC";	
			echo '<script type="text/javascript">window.location = "'.$tracking_url.$track_id.'" </script>';
			
		}elseif ($cc == "swyft-logistics" and ($order_status == "processing" or $order_status == "shipped" or $order_status == "delivered" or $order_status == "completed")){
			// echo "SL";
			echo '<script type="text/javascript">window.location = "'.$tracking_url.$track_id.'" </script>';
			
		}elseif ($cc == "vcs" and ($order_status == "processing" or $order_status == "shipped" or $order_status == "delivered" or $order_status == "completed")){
			//	echo "VCS";
		}				
}
else
{
	$invalid_order = "This is not a valid Order Number";
}

?>
<?php
get_header();
?>
<div id="Content">
	<div class="content_wrapper clearfix">

		<div class="sections_group">

			<div class="entry-content" itemprop="mainContentOfPage">

				<div class="section the_content has_content"><div class="section_wrapper"><div class="the_content_wrapper">
					<?php
while ( have_posts() ) {
?>
	<div style="text-align: center;">
		<br /><br />
		<h4>The current status of your Order Number <?php echo  $order_id;?></h4>
		<h3>
		<?php if ( empty($invalid_order) ) {?>
			<?php echo strtoupper($order_status); ?>
		<?php }else {?>
			<?php echo $invalid_order;
					}?>
		</h3>		
		Please visit later for updated status.
		<br /><br />
		Or <a href="<?php echo site_url()?>/contact-us/" >contact us</a> for any further detail.
	</div>
	<br /><hr><?php

    the_post();

    $mfn_builder = new Mfn_Builder_Front( get_the_ID() );
    $mfn_builder->show();
	
}

?>
					
</div></div></div>
				<div class="section section-page-footer">
					<div class="section_wrapper clearfix">

						<div class="column one page-pager">
													</div>

					</div>
				</div>

			</div>

			
		</div>

		
	</div>
</div>
<?php get_footer();