WC_Brands::output_product_brand_list()publicWC 1.0

Displays product brand list.

Метод класса: WC_Brands{}

Возвращает

Строку.

Использование

$WC_Brands = new WC_Brands();
$WC_Brands->output_product_brand_list( $atts );
$atts(массив) (обязательный)
Attributes from the shortcode.

Код WC_Brands::output_product_brand_list() WC 9.4.2

public function output_product_brand_list( $atts ) {
	$args = shortcode_atts(
		array(
			'show_top_links'    => true,
			'show_empty'        => true,
			'show_empty_brands' => false,
		),
		$atts
	);

	$show_top_links    = $args['show_top_links'];
	$show_empty        = $args['show_empty'];
	$show_empty_brands = $args['show_empty_brands'];

	if ( 'false' === $show_top_links ) {
		$show_top_links = false;
	}

	if ( 'false' === $show_empty ) {
		$show_empty = false;
	}

	if ( 'false' === $show_empty_brands ) {
		$show_empty_brands = false;
	}

	$product_brands = array();
        //phpcs:disable
	$terms          = get_terms( array( 'taxonomy' => 'product_brand', 'hide_empty' => ( $show_empty_brands ? false : true ) ) );
	$alphabet       = apply_filters( 'woocommerce_brands_list_alphabet', range( 'a', 'z' ) );
	$numbers        = apply_filters( 'woocommerce_brands_list_numbers', '0-9' );

	/**
	 * Check for empty brands and remove them from the list.
	 */
	if ( ! $show_empty_brands ) {
		$terms = $this->remove_terms_with_empty_products( $terms );
	}

	foreach ( $terms as $term ) {
		$term_letter = $this->get_brand_name_first_character( $term->name );

		// Allow a locale to be set for ctype_alpha().
		if ( has_filter( 'woocommerce_brands_list_locale' ) ) {
			setLocale( LC_CTYPE, apply_filters( 'woocommerce_brands_list_locale', 'en_US.UTF-8' ) );
		}

		if ( ctype_alpha( $term_letter ) ) {

			foreach ( $alphabet as $i ) {
				if ( $i == $term_letter ) {
					$product_brands[ $i ][] = $term;
					break;
				}
			}
		} else {
			$product_brands[ $numbers ][] = $term;
		}
	}

	ob_start();

	wc_get_template(
		'shortcodes/brands-a-z.php',
		array(
			'terms'          => $terms,
			'index'          => array_merge( $alphabet, array( $numbers ) ),
			'product_brands' => $product_brands,
			'show_empty'     => $show_empty,
			'show_top_links' => $show_top_links,
		),
		'woocommerce',
		WC()->plugin_path() . '/templates/brands/'
	);

	return ob_get_clean();
}