class="dashicon dashicons-arrow-right-alt2" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" > '; return $output; } /** * Render dropdown options list. * * @param array $categories List of terms. * @param array $attributes Block attributes. Default empty array. * @param int $uid Unique ID for the rendered block, used for HTML IDs. * @param int $depth Current depth. * @return string Rendered output. */ protected function renderDropdownOptions( $categories, $attributes, $uid, $depth = 0 ) { $output = ''; foreach ( $categories as $category ) { $output .= ' ' . ( ! empty( $category->children ) ? $this->renderDropdownOptions( $category->children, $attributes, $uid, $depth + 1 ) : '' ) . ' '; } return $output; } /** * Render the category list as a list. * * @param array $categories List of terms. * @param array $attributes Block attributes. Default empty array. * @param int $uid Unique ID for the rendered block, used for HTML IDs. * @param int $depth Current depth. * @return string Rendered output. */ protected function renderList( $categories, $attributes, $uid, $depth = 0 ) { $classes = [ 'wc-block-product-categories-list', 'wc-block-product-categories-list--depth-' . absint( $depth ), ]; if ( ! empty( $attributes['hasImage'] ) ) { $classes[] = 'wc-block-product-categories-list--has-images'; } $output = ''; return $output; } /** * Render a list of terms. * * @param array $categories List of terms. * @param array $attributes Block attributes. Default empty array. * @param int $uid Unique ID for the rendered block, used for HTML IDs. * @param int $depth Current depth. * @return string Rendered output. */ protected function renderListItems( $categories, $attributes, $uid, $depth = 0 ) { $output = ''; $link_color_class_and_style = StyleAttributesUtils::get_link_color_class_and_style( $attributes ); $link_color_style = isset( $link_color_class_and_style['style'] ) ? $link_color_class_and_style['style'] : ''; foreach ( $categories as $category ) { $output .= '
  • ' . $this->get_image_html( $category, $attributes ) . '' . esc_html( $category->name ) . '' . '' . $this->getCount( $category, $attributes ) . ( ! empty( $category->children ) ? $this->renderList( $category->children, $attributes, $uid, $depth + 1 ) : '' ) . '
  • '; } return preg_replace( '/\r|\n/', '', $output ); } /** * Returns the category image html * * @param \WP_Term $category Term object. * @param array $attributes Block attributes. Default empty array. * @param string $size Image size, defaults to 'woocommerce_thumbnail'. * @return string */ public function get_image_html( $category, $attributes, $size = 'woocommerce_thumbnail' ) { if ( empty( $attributes['hasImage'] ) ) { return ''; } $image_id = get_term_meta( $category->term_id, 'thumbnail_id', true ); if ( ! $image_id ) { return '' . wc_placeholder_img( 'woocommerce_thumbnail' ) . ''; } return '' . wp_get_attachment_image( $image_id, 'woocommerce_thumbnail' ) . ''; } /** * Get the count, if displaying. * * @param object $category Term object. * @param array $attributes Block attributes. Default empty array. * @return string */ protected function getCount( $category, $attributes ) { if ( empty( $attributes['hasCount'] ) ) { return ''; } if ( $attributes['isDropdown'] ) { return '(' . absint( $category->count ) . ')'; } $screen_reader_text = sprintf( /* translators: %s number of products in cart. */ _n( '%d product', '%d products', absint( $category->count ), 'woocommerce' ), absint( $category->count ) ); return '' . '' . '' . esc_html( $screen_reader_text ) . '' . ''; } }