woo_widget_cssclass = 'widget_layered_nav'; $this->woo_widget_description = __( 'Shows a custom attribute in a widget which lets you narrow down the list of products when viewing product categories.', 'woothemes' ); $this->woo_widget_idbase = 'woocommerce_layered_nav'; $this->woo_widget_name = __('WooCommerce Layered Nav', 'woothemes' ); /* Widget settings. */ $widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description ); /* Create the widget. */ $this->WP_Widget('layered_nav', $this->woo_widget_name, $widget_ops); } /** @see WP_Widget::widget */ function widget( $args, $instance ) { extract($args); if (!is_tax( 'product_cat' ) && !is_post_type_archive('product') && !is_tax( 'product_tag' )) return; global $_chosen_attributes, $wpdb, $woocommerce_query; $title = $instance['title']; $taxonomy = woocommerce::attribute_name($instance['attribute']); if (!taxonomy_exists($taxonomy)) return; $title = apply_filters('widget_title', $title, $instance, $this->id_base); $args = array( 'hide_empty' => '1' ); $terms = get_terms( $taxonomy, $args ); $count = count($terms); if($count > 0){ $found = false; ob_start(); echo $before_widget . $before_title . $title . $after_title; echo ""; echo $after_widget; if (!$found) : ob_clean(); return; else : $widget = ob_get_clean(); echo $widget; endif; } } /** @see WP_Widget::update */ function update( $new_instance, $old_instance ) { if (!isset($new_instance['title']) || empty($new_instance['title'])) $new_instance['title'] = woocommerce::attribute_label($new_instance['attribute']); $instance['title'] = strip_tags(stripslashes($new_instance['title'])); $instance['attribute'] = stripslashes($new_instance['attribute']); return $instance; } /** @see WP_Widget::form */ function form( $instance ) { global $wpdb; ?>