Automattic\WooCommerce\Blocks

CoreBreadcrumbsCompatibility::replace_product_archive_breadcrumb_label │ private │ WC 1.0

Replace product archive breadcrumb labels with the WooCommerce shop page title.

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

Хуков нет.

Возвращает

array. Modified breadcrumb items.

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

// private - только в коде основоного (родительского) класса
$result = $this->replace_product_archive_breadcrumb_label( $items );
$items(массив) (обязательный)
Array of breadcrumb items from Core.

Код CoreBreadcrumbsCompatibility::replace_product_archive_breadcrumb_label() WC 11.2.1

private function replace_product_archive_breadcrumb_label( $items ) {
	$shop_url = get_post_type_archive_link( 'product' );

	if ( ! $shop_url || null === $this->get_breadcrumb_item_index_by_url( $items, $shop_url ) ) {
		return $items;
	}

	$shop_page_item = $this->get_shop_page_breadcrumb_item( $shop_url );

	if ( empty( $shop_page_item ) ) {
		return $items;
	}

	foreach ( $items as $index => $item ) {
		if ( self::are_breadcrumb_urls_equal( $item['url'] ?? '', $shop_page_item['url'] ) ) {
			$items[ $index ]['label'] = $shop_page_item['label'];
		}
	}

	return $items;
}