'', 'online_shop_featured_cats' => array(), 'post_number' => 4, 'column_number' => 4, 'display_type' => 'column', 'wc_cat_display_option' => 'disable', 'orderby' => 'date', 'order' => 'DESC', 'view_all_option' => 'disable', 'all_link_text' => '', 'all_link_url' => '', 'enable_prev_next' => 1, 'online_shop_img_size' => 'shop_catalog' ); function __construct() { parent::__construct( /*Base ID of your widget*/ 'online_shop_wc_cats_tabs', /*Widget name will appear in UI*/ esc_html__('AT WooCommerce Cats Tabs', 'online-shop'), /*Widget description*/ array( 'description' => esc_html__( 'Show WooCommerce Category and Product on Tabs', 'online-shop' ), ) ); } /*Widget Backend*/ public function form( $instance ) { $instance = wp_parse_args( (array) $instance, $this->defaults); $online_shop_widget_title = esc_attr( $instance['online_shop_widget_title'] ); $online_shop_featured_cats = array_map( 'esc_attr', $instance['online_shop_featured_cats'] ); $post_number = absint( $instance[ 'post_number' ] ); $column_number = absint( $instance[ 'column_number' ] ); $display_type = esc_attr( $instance[ 'display_type' ] ); $wc_cat_display_option = esc_attr( $instance[ 'wc_cat_display_option' ] ); $orderby = esc_attr( $instance[ 'orderby' ] ); $order = esc_attr( $instance[ 'order' ] ); $view_all_option = esc_attr( $instance[ 'view_all_option' ] ); $all_link_text = esc_attr( $instance['all_link_text'] ); $all_link_url = esc_url( $instance['all_link_url'] ); $enable_prev_next = esc_attr( $instance['enable_prev_next'] ); $online_shop_img_size = esc_attr( $instance['online_shop_img_size'] ); $choices = online_shop_get_image_sizes_options(); ?>

'product_cat', 'hide_empty' => false, 'number' => 999 ); $woocommerce_categories_obj = get_categories( $args ); foreach( $woocommerce_categories_obj as $category ) { $at_option_name = $category->term_id; $at_option_title = $category->name; if( isset( $online_shop_featured_cats[$at_option_name] ) ) { $online_shop_featured_cats[$at_option_name] = 1; }else{ $online_shop_featured_cats[$at_option_name] = 0; } ?>

/>



/>

thumb; } /** * Function to Creating widget front-end. This is where the action happens * * @access public * @since 1.0.0 * * @param array $args widget setting * @param array $instance saved values * @return void * */ public function widget($args, $instance) { $instance = wp_parse_args( (array) $instance, $this->defaults); $online_shop_widget_title = !empty( $instance['online_shop_widget_title'] ) ? esc_attr( $instance['online_shop_widget_title'] ) : ''; $online_shop_widget_title = apply_filters( 'widget_title', $online_shop_widget_title, $instance, $this->id_base ); $online_shop_featured_cats = array_map( 'esc_attr', $instance['online_shop_featured_cats'] ); $post_number = absint( $instance[ 'post_number' ] ); $column_number = absint( $instance[ 'column_number' ] ); $display_type = esc_attr( $instance[ 'display_type' ] ); $wc_cat_display_option = esc_attr( $instance[ 'wc_cat_display_option' ] ); $orderby = esc_attr( $instance[ 'orderby' ] ); $order = esc_attr( $instance[ 'order' ] ); $view_all_option = esc_attr( $instance[ 'view_all_option' ] ); $all_link_text = esc_html( $instance[ 'all_link_text' ] ); $all_link_url = esc_url( $instance[ 'all_link_url' ] ); $enable_prev_next = esc_attr( $instance['enable_prev_next'] ); $this->thumb = $online_shop_img_size = esc_attr( $instance['online_shop_img_size'] ); /*test start*/ echo $args['before_widget']; if(!empty( $online_shop_featured_cats ) ){ if ( !empty( $online_shop_widget_title ) || 'disable' != $view_all_option || ( 1 == $enable_prev_next && 'carousel' == $display_type ) ){ echo $args['before_title']; echo $online_shop_widget_title; echo ''; echo ""; $i = 0; foreach ( $online_shop_featured_cats as $term_id => $value ){ $taxonomy = 'product_cat'; $term = get_term_by( 'id', $term_id, $taxonomy ); if ( $term && ! is_wp_error( $term ) ) { $term_name = $term->name; $active = ( $i == 0 ? ' active' : ''); echo ""; echo esc_html( $term_name ); echo ""; $i++; } } if( 'disable' != $view_all_option && !empty( $all_link_text ) && !empty( $all_link_url )){ $target =''; if( 'new-tab-link' == $view_all_option ){ $target = 'target="_blank"'; } echo ''.$all_link_text.''; } if( 1 == $enable_prev_next && 'carousel' == $display_type){ echo ''; } echo "";/*.at-action-wrapper*/ echo $args['after_title']; } $i = 0; foreach ( $online_shop_featured_cats as $term_id => $value ) { $active = ( $i == 0 ? ' active' : ''); /** * Filter the arguments for the Recent Posts widget. * * @since 1.0.0 * * @see WP_Query * */ $query_args = array( 'posts_per_page' => $post_number, 'post_status' => 'publish', 'post_type' => 'product', 'no_found_rows' => 1, 'order' => $order, 'meta_query' => array(), 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $term_id, ) ), ); switch ( $orderby ) { case 'price' : $query_args['meta_key'] = '_price'; $query_args['orderby'] = 'meta_value_num'; break; case 'sales' : $query_args['meta_key'] = 'total_sales'; $query_args['orderby'] = 'meta_value_num'; break; case 'ID' : case 'author' : case 'title' : case 'date' : case 'modified' : case 'rand' : case 'comment_count' : case 'menu_order' : $query_args['orderby'] = $orderby; break; default : $query_args['orderby'] = 'date'; } $online_shop_featured_query = new WP_Query( $query_args ); if ($online_shop_featured_query->have_posts()) : $div_attr = 'class="featured-entries-col woocommerce '.$display_type.'"'; if( 'carousel' == $display_type ){ $div_attr = 'class="featured-entries-col woocommerce acme-slick-carausel" data-column="'.absint( $column_number ).'"'; } echo "
"; if( 'disable' != $wc_cat_display_option ){ $taxonomy = 'product_cat'; $term_id = absint($term_id); $term_link = get_term_link( $term_id, $taxonomy ); $term = get_term( $term_id, $taxonomy ); $thumbnail_id = get_term_meta( $term_id, 'thumbnail_id', true); if ( !empty( $thumbnail_id ) ) { $image_url = wp_get_attachment_image_src($thumbnail_id, 'full'); } else{ $image_url[0] = get_template_directory_uri() . '/assets/img/default-image.jpg'; } ?>
name ) ) { ?>

name ); ?>

> have_posts() ) :$online_shop_featured_query->the_post(); $online_shop_list_classes = 'single-list'; if( 'carousel' != $display_type ){ if( 1 != $online_shop_featured_index && $online_shop_featured_index % $column_number == 1 ){ echo "
"; } if( 1 == $column_number ){ $online_shop_list_classes .= " acme-col-1"; } elseif( 2 == $column_number ){ $online_shop_list_classes .= " acme-col-2"; } elseif( 3 == $column_number ){ $online_shop_list_classes .= " acme-col-3"; } else{ $online_shop_list_classes .= " acme-col-4"; } } ?>
";/*.at-tabs-wrap*/ // Reset the global $the_post as this query will have stomped on it endif; wp_reset_postdata(); $i++; } } /*test end*/ echo $args['after_widget']; echo "
"; } } // Class Online_Shop_Wc_Cats_Tabs ends here }