__( "Shows a custom attribute in a widget which lets you narrow down the list of shown products in categories.", 'woothemes') ); parent::WP_Widget('layered_nav', __('WooCommerce Layered Nav', 'woothemes'), $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, $all_post_ids; $title = $instance['title']; $taxonomy = 'product_attribute_'.strtolower(sanitize_title($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'] = ucwords($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; ?>