<?php 
namespace WCQT\classes\admin;


class OrdersTablePage 
{
	var $already_invoked = false;
	public function __construct ()
	{
		//HPOS
		add_filter('woocommerce_order_list_table_prepare_items_query_args', array( &$this,'filter_order_list_query'));
		//
		add_filter('parse_query',array( $this,'filter_query'));																		//For HPOS managed by filter_order_list_query
		
	}
	function filter_query($query) 
	{
		global $pagenow, $wcqt_order_model;
		$quote_statuses = $wcqt_order_model->get_quote_statuses();
		
		$qv = &$query->query_vars;
		if ($pagenow=='edit.php' && 
		    isset($qv['post_type']) && $qv['post_type']=='shop_order' ) 
			{
				if($this->already_invoked)
				return;
			
				$this->already_invoked = true;
				if(is_array($qv["post_status"]))
					foreach($qv["post_status"] as $key => $value)
						if(isset($quote_statuses[$value]))
							unset($qv['post_status'][$key]);
			}
			
		return $query;
	}
	//HPOS
	function filter_order_list_query($query) 
	{
		if($this->already_invoked)
				return;
		
		global $wcqt_order_model;
		$quote_statuses = $wcqt_order_model->get_quote_statuses();
		
		$this->already_invoked = true;
		if(is_array($query['status']))
			foreach($query['status'] as $key => $value)
				if(isset($quote_statuses[$value]))
					unset($query['status'][$key]);
		
		return $query;
	}
}
?>