'ample-construction-featured-product', 'description' => esc_html__( 'Add Widget to Display WooCommerce Featured Product.', 'ample-construction' ) ); parent::__construct( 'ample_construction_featured_product',esc_html__( 'AC: Featured Product', 'ample-construction' ), $widget_ops, $control_ops ); } function form( $instance ) { $defaults[ 'title' ] = ''; $defaults[ 'subtitle' ] = ''; $defaults[ 'product_type' ] = ''; $defaults[ 'category' ] = ''; $defaults[ 'product_number' ] = 10; $defaults[ 'hide_thumbnail_mask' ] = 0; $instance = wp_parse_args( (array) $instance, $defaults ); $title = esc_attr( $instance[ 'title' ] ); $subtitle = esc_textarea( $instance[ 'subtitle' ] ); $product_type = $instance[ 'product_type' ]; $category = absint( $instance[ 'category' ] ); $product_number = absint( $instance[ 'product_number' ] ); $hide_thumbnail_mask = $instance[ 'hide_thumbnail_mask' ] ? 'checked="checked"' : ''; ?>
'', 'show_option_all' => esc_html__('Select','ample-construction'), '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 ), ); } ?>