'agency_ecommerce_widget_woo_categories', 'description' => esc_html__('Widget to display categories of WooCommerce.', 'agency-ecommerce'), ); parent::__construct('agency-ecommerce-woo-categories', esc_html__('AE - WOO Categories', 'agency-ecommerce'), $opts); } function widget_fields() { $fields = array( 'title' => array( 'name' => 'title', 'title' => esc_html__('Title', 'agency-ecommerce'), 'type' => 'text', 'default' => esc_html__('Product Category', 'agency-ecommerce'), ), 'product_category' => array( 'name' => 'product_category', 'title' => esc_html__('Product Category', 'agency-ecommerce'), 'type' => 'dropdown_categories', 'args' => array( 'taxonomy' => 'product_cat', 'hide_empty' => true, 'orderby' => 'name', 'multiple' => true ), 'default' => array(0) ), 'view_details' => array( 'name' => 'view_details', 'title' => esc_html__('View Details Text', 'agency-ecommerce'), 'type' => 'text', 'default' => esc_html__('View Details', 'agency-ecommerce') ), 'show_counts' => array( 'name' => 'show_counts', 'title' => esc_html__('Show Counts', 'agency-ecommerce'), 'type' => 'checkbox', ), 'disable_carousel' => array( 'name' => 'disable_carousel', 'title' => esc_html__('Disable Carousel', 'agency-ecommerce'), 'type' => 'checkbox', ), 'background_color' => array( 'name' => 'background_color', 'title' => esc_html__('Background Color', 'agency-ecommerce'), 'type' => 'color', 'default' => '#ffffff' ) ); return $fields; } function widget($args, $instance) { $valid_widget_instance = Agency_Ecommerce_Widget_Validation::instance()->validate($instance, $this->widget_fields()); $title = apply_filters('widget_title', empty($valid_widget_instance['title']) ? '' : $valid_widget_instance['title'], $valid_widget_instance, $this->id_base); $product_category = $valid_widget_instance['product_category']; if (count($product_category) == 1 && $product_category[0] == 0) { $product_category = array(); $cat_args = array( 'taxonomy' => 'product_cat', 'orderby' => 'name', 'hide_empty' => true ); $all_categories = get_categories($cat_args); $product_category = count($all_categories) > 0 ? wp_list_pluck($all_categories, 'term_id') : array(); } $disable_carousel = $valid_widget_instance['disable_carousel']; $background_color = $valid_widget_instance['background_color']; $args['before_widget'] = str_replace('class="', 'style="background:' . esc_attr($background_color) . ' " class="', $args['before_widget']); echo $args['before_widget']; ?>