'blog-nano-featured-product', 'description' => esc_html__( 'Add Widget to Display WooCommerce Featured Product.', 'blog-nano' ) ); parent::__construct( 'blog_nano_featured_product',esc_html__( 'TM: Featured Product Widget', 'blog-nano' ), $widget_ops, $control_ops ); } function form( $instance ) { $defaults[ 'title' ] = ''; $defaults[ 'product_type' ] = ''; $defaults[ 'category' ] = ''; $defaults[ 'product_number' ] = 10; $instance = wp_parse_args( (array) $instance, $defaults ); $title = esc_attr( $instance[ 'title' ] ); $product_type = sanitize_text_field($instance[ 'product_type' ]); $category = absint( $instance[ 'category' ] ); $product_number = absint( $instance[ 'product_number' ] ); ?>

'', 'show_option_all' => esc_html__('Select','blog-nano'), 'name' => $this->get_field_name( 'category' ), 'selected' => $instance['category'], 'taxonomy' => 'product_cat' ) ); ?>

0 ) { $term = get_term( $category ); $slug = $term->slug; } if ( $product_type == 'featured' ) { $args = array( 'post_type' => 'product', 'posts_per_page' => absint( $product_number ), 'tax_query' => array( array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured', ), ) ); if ( absint( $category ) > 0 ) { $args['product_cat'] = esc_attr( $slug); } } elseif ( $product_type == 'sale' ) { $args = array( 'post_type' => 'product', 'meta_query' => array( 'relation' => 'OR', array( // Simple products type 'key' => '_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ), array( // Variable products type 'key' => '_min_variation_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ) ), 'posts_per_page' => absint( $product_number ), ); if ( absint( $category ) > 0 ) { $args['product_cat'] = esc_attr( $slug); } } elseif ( $product_type == 'category' ){ $args = array( 'post_type' => 'product', 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'id', 'terms' => absint( $category ), ) ), 'posts_per_page' => absint( $product_number ), ); } elseif ( $product_type == 'seller' ) { $args = array( 'post_type' => 'product', 'meta_key' => 'total_sales', 'orderby' => 'meta_value_num', 'posts_per_page' => absint( $product_number ), ); if ( absint( $category ) > 0 ) { $args['product_cat'] = esc_attr( $slug); } } else { $args = array( 'post_type' => 'product', 'posts_per_page' => absint( $product_number ), ); } ?>

have_posts()) : $featured_query->the_post(); $product = wc_get_product( $featured_query->post->ID ); $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,'blog-nano-product-carousel', false);?>

get_price_html() ) : ?> get_id() ); ?>