<?php
ob_start();
require_once('../../../../wp-config.php');
include "getproductdetail-do.php";

$product_id = $_POST["product_id"];

 $category = $_POST["category"];
// echo "<hr >";
 $pa_color = $_POST["pa_color"];
// echo "<hr >";
 $pa_size = $_POST["pa_size"];

if ($category == "null" and $product_id == 0 and $pa_color == "null" and $pa_size == "null" ){
	echo "Select a filter";
	exit();
}
if ($product_id == 0 and $pa_color == "null" and $pa_size == "null" ){
	echo "Select proper filter";
	exit();
}

// echo "<hr >";

if ($product_id > 0 ){
	getproductdetail($product_id);}
elseif ($pa_color == "null" and $pa_size == "null" ){
	getproductdetail($product_id);
}else{
	// echo "--- HERE ---<hr >";	
	if ($category <> "null"){
		$product_cat[] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array($category), 'compare' => 'IN' );	 
		}
	if ($pa_color <> "null"){
		$pa_color1[] = array( 'taxonomy' => 'pa_color', 'field' => 'slug', 'terms' => $pa_color, 'compare' => 'IN' );
		}
	if ($pa_size <> "null" ){
		$pa_size1[] = array( 'taxonomy' => 'pa_size', 'field' => 'slug', 'terms' => $pa_size, 'compare' => 'IN' );
		}
		 
	 
	$args = array(
		//'meta_compare' => 'LIKE',
		'post_type'      => 'product',
		'posts_per_page' => '10000',
		'orderby' => 'title',
		'order' => 'ASC',
		'tax_query'           => array(
	   'relation'=>'AND', // 'AND' 'OR' ...
		$product_cat,
		$pa_color1,
		$pa_size1
	  )
	);
	
	// print_r ($args);
	// echo "<hr />";
	
	$loop = new WP_Query( $args );

	if ( $loop->have_posts() ) {
		$i = 1;
		while ( $loop->have_posts() ) : $loop->the_post();
			{
					getproductdetail(get_the_id(), $instock);
			?>

<?php /*?>				<a href="<?php echo get_the_permalink();?>" target="new"><?php echo $i++	.'. '.get_the_id(). ' '.get_the_title(); ?></a>	<?php */?>
	 		<?php
				echo "<br />";
			}
		endwhile;
	} else {
		echo "NOT FOUND";
	}

}

?>