widget_cssclass = 'woocommerce best_shop_product_carousel_tab_widget';
$this->widget_description = __( 'Display Product Carousel.', 'best-shop' );
$this->widget_id = 'best_shop_product_carousel_tab_widget';
$this->widget_name = __( '+ Gradient Product Carousel', 'best-shop' );
parent::__construct();
}
public function widget( $args, $instance ) {
if(is_admin() ) {
?>
'product',
'post_status' => 'publish',
'posts_per_page'=> $max_items,
'order' => 'DESC',
);
switch($category){
case 'featured':
$product_args['tax_query'] = array(array('taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured'));
break;
case 'best_selling':
$product_args['meta_key'] = 'total_sales';
$product_args['orderby'] = 'meta_value_num';
break;
case 'on_sale':
$product_args['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'
)
) ;
break;
case 'latest':
$product_args['orderby'] = 'date';
$product_args['order']= 'DESC';
break;
case 'top_rated':
$product_args['meta_query'] = WC()->query->get_meta_query();
$product_args['orderby'] = 'meta_value_num';
$product_args['meta_key'] = '_wc_average_rating';
break;
//heigh to low
case 'price':
$product_args['orderby'] = 'meta_value_num';
$product_args['meta_key'] = '_price';
break;
}
} else {
//category
if ($category == '-1') {
$product_args = array('post_type' => 'product',
'post_status' => 'publish',
'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 )));
}
}
//print_r($product_args);
if(!$pagination) { $product_shortcode1 = str_replace("paginate=true", " paginate=false", $product_shortcode1); }
if(!$pagination) { $product_shortcode2 = str_replace("paginate=true", " paginate=false", $product_shortcode2); }
if(!$pagination) { $product_shortcode3 = str_replace("paginate=true", " paginate=false", $product_shortcode3); }
best_shop_create_slider( $product_args, $products_per_slide, $hide_navigation, $hide_dots );
}
public function form( $instance ) {
$max_items = ( ! empty( $instance['max_items'] ) ) ? absint( $instance['max_items'] ) : 5;
$category = ( ! empty( $instance['category'] ) ) ? wp_strip_all_tags( $instance['category'] ) : -1;
$hide_navigation = ( ! empty( $instance['hide_navigation'] )) ? (bool) $instance['hide_navigation'] : false;
$hide_dots = ( ! empty( $instance['hide_dots'] )) ? (bool) $instance['hide_dots'] : false;
$products_per_slide = (!empty($instance['products_per_slide'])) ? absint($instance['products_per_slide']) : 4;
$button_lbl = ( ! empty( $instance['button_lbl'] ) ) ? wp_strip_all_tags( $instance['button_lbl'] ) : esc_html__('VIEW PRODUCT', 'best-shop');
$args = array( 'taxonomy' => 'product_cat',
'orderby' => 'date',
'order' => 'ASC',
'show_count' => 1,
'pad_counts' => 0,
'hierarchical' => 0,
'title_li' => '',
'hide_empty' => 1,
);
$categories = get_categories( $args );
$category_list = '';
$categories = best_shop_get_product_category_list();
if(0 == $category){
//$category_list = $category_list.'';
} else{
//$category_list = $category_list.'';
}
foreach ( $categories as $cat=> $value ) {
$selected ='';
if(($cat)==$category){
$selected ='Selected=selected';
}
$category_list = $category_list.'';
}
?>
id="get_field_id( 'hide_navigation' )); ?>" name="get_field_name( 'hide_navigation' )); ?>" />
id="get_field_id( 'hide_dots' )); ?>" name="get_field_name( 'hide_dots' )); ?>" />