/** * Filter products by brand, uses slugs for option values. * * @access public * @return void */ function dhwc_products_by_brand() { global $typenow, $wp_query; if ($typenow == 'product') { dhwc_product_dropdown_brands($show_counts = 1, $hierarchical = 1, $show_uncategorized = 0); } }
/** * (non-PHPdoc) * @see wp-includes/WP_Widget::widget() */ public function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Product brands', DHVC_WOO) : $instance['title'], $instance, $this->id_base); $c = $instance['count'] ? '1' : '0'; $h = $instance['hierarchical'] ? true : false; $s = isset($instance['show_children_only']) && $instance['show_children_only'] ? '1' : '0'; $d = $instance['dropdown'] ? '1' : '0'; $o = isset($instance['orderby']) ? $instance['orderby'] : 'order'; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $brand_args = array('show_count' => $c, 'hierarchical' => $h, 'taxonomy' => 'product_brand'); $brand_args['menu_order'] = false; if ($o == 'order') { $brand_args['menu_order'] = 'asc'; } else { $brand_args['orderby'] = 'title'; } if ($d) { dhwc_product_dropdown_brands($c, $h, 0, $o); ?> <script type='text/javascript'> /* <![CDATA[ */ var product_brand_dropdown = document.getElementById("dropdown_product_brand"); function onProductBrandChange() { if ( product_brand_dropdown.options[product_brand_dropdown.selectedIndex].value !=='' ) { location.href = "<?php echo home_url(); ?> /?product_brand="+product_brand_dropdown.options[product_brand_dropdown.selectedIndex].value; } } product_brand_dropdown.onchange = onProductBrandChange; /* ]]> */ </script> <?php } else { global $wp_query, $post, $woocommerce; $this->current_brand = false; $this->brand_ancestors = array(); if (is_tax('product_brand')) { $this->current_brand = $wp_query->queried_object; $this->brand_ancestors = get_ancestors($this->current_brand->term_id, 'product_brand'); } elseif (is_singular('product')) { $product_brand = wc_get_product_terms($post->ID, 'product_brand', array('orderby' => 'parent')); if ($product_brand) { $this->current_brand = end($product_brand); $this->brand_ancestors = get_ancestors($this->current_brand->term_id, 'product_brand'); } } include_once dirname(__FILE__) . '/dhwc_product_brand_list_walker.php'; $brand_args['walker'] = new DHWC_Product_Brand_List_Walker(); $brand_args['title_li'] = ''; $brand_args['show_children_only'] = isset($instance['show_children_only']) && $instance['show_children_only'] ? 1 : 0; $brand_args['pad_counts'] = 1; $brand_args['show_option_none'] = __('No product brands exist.', DHVC_WOO); $brand_args['current_brand'] = $this->current_brand ? $this->current_brand->term_id : ''; $brand_args['current_brand_ancestors'] = $this->brand_ancestors; echo '<ul class="product-brands">'; dhwc_list_brands(apply_filters('dhwc_product_brands_widget_args', $brand_args)); echo '</ul>'; } echo $after_widget; }