<?php
function shop_special_products( $atts ){
    global $woocommerce_loop;

    extract( shortcode_atts( array(
		"type" 			=> 3,
        'limit'      	=> 12,
        'columns'       => 4,
        'orderby'       => 'title',
        'order'         => 'asc',
		'automatic' 	=> 'false',
		'items' 		=> "4",
		'interval' 		=> "2500",
		'showarrows' 	=> "false",
		'anim'			=> '',
		'class'			=>''
        ), $atts ) );
	
    $args = array(
        'post_type' => 'product',
        'post_status' => 'publish',
        'ignore_sticky_posts'   => 1,
        'posts_per_page' => $limit,
    );
	if($automatic=='true'){
		$out=' data-carousel-autoplay="'.$interval.'"';
	}else{
		$out='data-carousel-autoplay="false"';
	}
	if ($type == 1){ // Products on Sale
		$args['orderby'] = $orderby;
        $args['order' ] = $order;
		$args['meta_query'] = array(
            array(
                'key' => '_visibility',
                'value' => array('catalog', 'visible'),
                'compare' => 'IN'
            ),
            array(
                'key' => '_sale_price',
                'value' => 0,
                'compare' => '>',
                'type' => 'NUMERIC'
            )
        );
	}
	elseif ($type == 2){ // Best selling products
		$args['meta_key'] 	= 'total_sales';
		$args['orderby']	= 'meta_value';
		$args['meta_query'] = array(
            array(
                'key' => '_visibility',
                'value' => array( 'catalog', 'visible' ),
                'compare' => 'IN'
            )
        );
	}
	
	elseif ($type == 3){ // Featured products
		$args['orderby'] = $orderby;
        $args['order' ] = $order;
		$args['meta_query'] = array(
			array(
				'key' => '_visibility',
				'value' => array('catalog', 'visible'),
				'compare' => 'IN'
			),
			array(
				'key' => '_featured',
				'value' => 'yes'
			)
		);
	}
	
	$anim=(!empty($anim)) ? 'animation '.$anim : '';
  	ob_start();

	
	$loop = new WP_Query( $args );

	?>


	<?php if ( $loop->have_posts() ) : $randomId = mt_rand(0, 100000);?>
		<div class="carousel-box <?php echo $anim.' '.$class ?> woocommerce shop-carousel special-carousel">
			<ul class="carousel carousel-simple" <?php echo $out?> data-carousel-items="<?php echo $items?>" data-carousel-nav="<?php echo $showarrows?>" data-carousel-pagination="false">
				<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
					<?php woocommerce_get_template_part( 'content', 'product' ); ?>
				<?php endwhile; // end of the loop. ?>
			</ul>
		</div>
	<?php else: ?>
		<p class="no-products"><?php _e('No products found.', 'trendystuff')?></p>
	<?php endif;?>
	
	<?php wp_reset_postdata();

	return ob_get_clean();
}
add_shortcode('shop_special_products', 'shop_special_products');
/*****************************************************/
vc_map( array(
   "name" => __("Woocommerce products listing by special type", "trendystuff"),
   "base" => "shop_special_products",
   "class" => "",
   "icon" => "icon-wpb-my_shop_special_products",
   'admin_enqueue_css' => array(get_template_directory_uri().'/vc_templates/shortcodes.css'),
   "category" => __('Content', "trendystuff"),
   "params" => array(
       array(
         "type" => "dropdown",
         "class" => "",
         "heading" => __("Animation", "trendystuff"),
         "param_name" => "anim",
         "value" => array( "None"=>"", "bounce"=>"bounce", "flash"=>"flash", "pulse"=>"pulse", "shake"=>"shake", "swing"=>"swing", "tada"=>"tada", "wobble"=>"wobble", "bounceIn"=>"bounceIn", "bounceInDown"=>"bounceInDown", "bounceInLeft"=>"bounceInLeft", "bounceInRight"=>"bounceInRight", "bounceInUp"=>"bounceInUp", "bounceOut"=>"bounceOut", "bounceOutDown"=>"bounceOutDown", "bounceOutLeft"=>"bounceOutLeft", "bounceOutRight"=>"bounceOutRight", "bounceOutUp"=>"bounceOutUp", "fadeIn"=>"fadeIn", "fadeInDown"=>"fadeInDown", "fadeInDownBig"=>"fadeInDownBig", "fadeInLeft"=>"fadeInLeft", "fadeInLeftBig"=>"fadeInLeftBig", "fadeInRight"=>"fadeInRight", "fadeInRightBig"=>"fadeInRightBig", "fadeInUp"=>"fadeInUp", "fadeInUpBig"=>"fadeInUpBig", "fadeOut"=>"fadeOut", "fadeOutDown"=>"fadeOutDown", "fadeOutDownBig"=>"fadeOutDownBig", "fadeOutLeft"=>"fadeOutLeft", "fadeOutLeftBig"=>"fadeOutLeftBig", "fadeOutRight"=>"fadeOutRight", "fadeOutRightBig"=>"fadeOutRightBig", "fadeOutUp"=>"fadeOutUp", "fadeOutUpBig"=>"fadeOutUpBig", "flip"=>"flip", "flipInX"=>"flipInX", "flipInY"=>"flipInY", "flipOutX"=>"flipOutX", "flipOutY"=>"flipOutY", "lightSpeedIn"=>"lightSpeedIn", "lightSpeedOut"=>"lightSpeedOut", "rotateIn"=>"rotateIn", "rotateInDownLeft"=>"rotateInDownLeft", "rotateInDownRight"=>"rotateInDownRight", "rotateInUpLeft"=>"rotateInUpLeft", "rotateInUpRight"=>"rotateInUpRight", "rotateOut"=>"rotateOut", "rotateOutDownLeft"=>"rotateOutDownLeft", "rotateOutDownRight"=>"rotateOutDownRight", "rotateOutUpLeft"=>"rotateOutUpLeft", "rotateOutUpRight"=>"rotateOutUpRight",  "hinge"=>"hinge", "rollIn"=>"rollIn", "rollOut"=>"rollOut", "zoomIn"=>"zoomIn","zoomInDown"=>"zoomInDown", "zoomInLeft"=>"zoomInLeft","zoomInRight"=>"zoomInRight","zoomInUp"=>"zoomInUp","zoomOut"=>"zoomOut", "zoomOutLeft"=>"zoomOutLeft", "zoomOutRight"=>"zoomOutRight","zoomOutUp"=>"zoomOutUp"),
         "description" => __(" Animation.", "trendystuff")
      ),
	   array(
         "type" => "dropdown", 
         "class" => "",
         "heading" => __("Listing type", "trendystuff"),
         "param_name" => "type",
         "value"=>array("On Sale"=>"1", "Best selling"=>"2", "Featured"=>"3")
      ),
	    array(
         "type" => "textfield",
         "class" => "",
         "heading" => __("Items limit", "trendystuff"),
         "param_name" => "limit",
		 "value"=>"12"
      ),
	   array(
         "type" => "textfield",
         "class" => "",
         "heading" => __("Items to Show", "trendystuff"),
         "param_name" => "items",
		 "value"=>"4"
      ),
	    array(
         "type" => "dropdown", 
         "class" => "",
         "heading" => __("Automatic sliding", "trendystuff"),
         "param_name" => "automatic",
         "value"=>array("No"=>"false", "Yes"=>"true")
      ),
	    array(
         "type" => "textfield",
         "class" => "",
         "heading" => __("Sliding interval", "trendystuff"),
         "param_name" => "interval",
		 "value"=>"2500"
      ),
	    array(
         "type" => "dropdown", 
         "class" => "",
         "heading" => __("Show arrows", "trendystuff"),
         "param_name" => "showarrows",
         "value"=>array("Yes"=>"true", "No"=>"false")
      ),
	    array(
         "type" => "dropdown", 
         "class" => "",
         "heading" => __("Order", "trendystuff"),
         "param_name" => "order",
         "value"=>array("Descending"=>"DESC", "Ascending"=>"ASC")
      ),
	  array(
         "type" => "dropdown", 
         "class" => "",
         "heading" => __("Order by", "trendystuff"),
         "param_name" => "orderby",
         "value"=>array("Default sorting"=>"menu_order", "Sort by popularity"=>"popularity", "Sort by average rating"=>"rating", "Sort by newness"=>"date", "Sort by price: low to high"=>"price", "Sort by price: high to low"=>"price-desc")
      ),
        array(
         "type" => "textfield",
         "class" => "",
         "heading" => __("Extra class", "trendystuff"),
         "param_name" => "class",
         "description" => __(' Extra class name', "trendystuff")
      )
   )
) );
?>