WC_Widget_Brand_Nav::widget()
Widget function.
Method of the class: WC_Widget_Brand_Nav{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Widget_Brand_Nav = new WC_Widget_Brand_Nav(); $WC_Widget_Brand_Nav->widget( $args, $instance );
- $args(array) (required)
- Arguments.
- $instance(array) (required)
- Widget instance.
Notes
- See: WP_Widget
WC_Widget_Brand_Nav::widget() WC Widget Brand Nav::widget code WC 9.5.1
public function widget( $args, $instance ) { $attribute_array = array(); $attribute_taxonomies = wc_get_attribute_taxonomies(); if ( ! empty( $attribute_taxonomies ) ) { foreach ( $attribute_taxonomies as $tax ) { if ( taxonomy_exists( wc_attribute_taxonomy_name( $tax->attribute_name ) ) ) { $attribute_array[ $tax->attribute_name ] = $tax->attribute_name; } } } if ( ! is_post_type_archive( 'product' ) && ! is_tax( array_merge( is_array( $attribute_array ) ? $attribute_array : array(), array( 'product_cat', 'product_tag' ) ) ) ) { return; } $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); $current_term = $attribute_array && is_tax( $attribute_array ) ? get_queried_object()->term_id : ''; $current_tax = $attribute_array && is_tax( $attribute_array ) ? get_queried_object()->taxonomy : ''; /** * Filter the widget's title. * * @since 9.4.0 * * @param string $title Widget title * @param array $instance The settings for the particular instance of the widget. * @param string $woo_widget_idbase The widget's id base. */ $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); $taxonomy = 'product_brand'; $display_type = isset( $instance['display_type'] ) ? $instance['display_type'] : 'list'; if ( ! taxonomy_exists( $taxonomy ) ) { return; } // Get only parent terms. Methods will recursively retrieve children. $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => true, 'parent' => 0, ) ); if ( empty( $terms ) ) { return; } ob_start(); $this->widget_start( $args, $instance ); if ( 'dropdown' === $display_type ) { $found = $this->layered_nav_dropdown( $terms, $taxonomy ); } else { $found = $this->layered_nav_list( $terms, $taxonomy ); } $this->widget_end( $args ); // Force found when option is selected - do not force found on taxonomy attributes. if ( ! is_tax() && is_array( $_chosen_attributes ) && array_key_exists( $taxonomy, $_chosen_attributes ) ) { $found = true; } if ( ! $found ) { ob_end_clean(); } else { echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput } }