'agency_ecommerce_widget_latest_products', 'description' => esc_html__( 'Widget to display latest product or featured products of Woo-Commerce with carousel', 'agency-ecommerce' ), ); parent::__construct( 'agency-ecommerce-latest-products', esc_html__( 'AE: Products Carousel', 'agency-ecommerce' ), $opts ); } function widget( $args, $instance ) { $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); $product_category = ! empty( $instance['product_category'] ) ? $instance['product_category'] : 0; $product_type = !empty( $instance['product_type'] ) ? $instance['product_type'] : ''; $product_number = ! empty( $instance['product_number'] ) ? $instance['product_number'] : 6; $disable_carousel = ! empty( $instance['disable_carousel'] ) ? $instance['disable_carousel'] : 0; echo $args['before_widget']; ?>
4, 'slidesToScroll'=> 4, 'dots' => true, 'arrows' => false, 'responsive' => array( array( 'breakpoint' => 1024, 'settings' => array( 'slidesToShow' => 4, ), ), array( 'breakpoint' => 992, 'settings' => array( 'slidesToShow' => 3, 'slidesToScroll'=> 3, ), ), array( 'breakpoint' => 768, 'settings' => array( 'slidesToShow' => 2, 'slidesToScroll'=> 2, ), ), array( 'breakpoint' => 479, 'settings' => array( 'slidesToShow' => 1, 'slidesToScroll'=> 1, ), ), ), ); $carousel_args_encoded = wp_json_encode( $carousel_args ); $meta_query = WC()->query->get_meta_query(); $tax_query = WC()->query->get_tax_query(); if( 'featured' == $product_type ){ $tax_query[] = array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured', 'operator' => 'IN', ); }else{ $tax_query[] = array( 'taxonomy' => 'product_cat', 'field' => 'id', 'terms' => absint( $product_category ), 'operator' => 'IN', ); } $query_args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => absint( $product_number ), 'meta_query' => $meta_query, 'no_found_rows' => true, ); if ( absint( $product_category ) > 0 || 'featured' == $product_type ) { $query_args['tax_query'] = $tax_query; } global $woocommerce_loop; $latest_products = new WP_Query( $query_args ); if ( $latest_products->have_posts() ) :?>
'', 'product_category' => '', 'product_type' => 'latest', 'product_number' => 6, 'disable_carousel' => 0, ) ); ?>

'name', 'hide_empty' => 0, 'class' => 'widefat', 'taxonomy' => 'product_cat', 'name' => $this->get_field_name( 'product_category' ), 'id' => $this->get_field_id( 'product_category' ), 'selected' => absint( $instance['product_category'] ), 'show_option_all' => esc_html__( 'All Categories','agency-ecommerce' ), ); wp_dropdown_categories( $cat_args ); ?>

dropdown_product_type( array( 'id' => $this->get_field_id( 'product_type' ), 'name' => $this->get_field_name( 'product_type' ), 'selected' => esc_attr( $instance['product_type'] ), ) ); ?>

id="get_field_id( 'disable_carousel' ); ?>" name="get_field_name( 'disable_carousel' ); ?>" />

'', 'class' => 'widefat', 'name' => '', 'selected' => 'latest', ); $r = wp_parse_args( $args, $defaults ); $output = ''; $choices = array( 'latest' => esc_html__( 'Latest', 'agency-ecommerce' ), 'featured' => esc_html__( 'Featured', 'agency-ecommerce' ), ); if ( ! empty( $choices ) ) { $output = "\n"; } echo $output; } } endif;