widget_cssclass = 'woocommerce best_shop_product_slider_widget'; $this->widget_description = __( 'Display Product Slider.', 'best-shop' ); $this->widget_id = 'best_shop_product_slider_widget'; $this->widget_name = __( '+ Product Slider', 'best-shop' ); parent::__construct(); } public function widget( $args, $instance ) { $max_items = ( ! empty( $instance['max_items'] ) ) ? absint( $instance['max_items'] ) : 5; $category = ( ! empty( $instance['category'] ) ) ? wp_strip_all_tags( $instance['category'] ) : -1; $hide_title_price = ( ! empty( $instance['hide_title_price'] ) ) ? true : false; $navigation = ( ! empty( $instance['navigation'] ) ) ? true : false; $max_height = (!empty($instance['max_height'])) ? absint($instance['max_height']) : 400; $speed = (!empty($instance['speed'])) ? absint($instance['speed']) : 4; $button_lbl = ( ! empty( $instance['button_lbl'] ) ) ? wp_strip_all_tags( $instance['button_lbl'] ) : esc_html__('VIEW PRODUCT', 'best-shop'); $operator = 'IN'; $product_args = array(); if( $category == -1 ){ $product_args = array ( 'post_type' => 'product', 'posts_per_page'=> $max_items ); } else { $product_args = array ( 'post_type' => 'product', 'posts_per_page'=> $max_items, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'terms' => $category, 'operator' => $operator ))); } $loop = new WP_Query($product_args ); $i = 1; $items = array(); while( $loop->have_posts() ) : $loop->the_post(); global $product; $thumb_id = get_post_thumbnail_id(get_the_ID()); $url = get_the_post_thumbnail_url(get_the_ID(), 'full'); if(!$url) { $url = get_template_directory_uri().'/images/empty.png'; } $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); $link = get_permalink(); $title = get_the_title(); $content = get_the_excerpt(); $price = $product->get_price_html(); $item = array( 'image_url' => $url, 'content' => $content, 'title' => $title, 'alt' => $alt, 'link' => $link, 'price_html' => $price); array_push($items, $item); $i++; endwhile; wp_reset_postdata(); global $best_shop_uniqueue_id ; $best_shop_uniqueue_id += 1; $carousal_id = 'product-carousal-'.$best_shop_uniqueue_id; //carousal begin echo '