Automattic\WooCommerce\Blocks

CoreBreadcrumbsCompatibility::replace_product_archive_breadcrumb_label │ private │ WC 1.0

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

Method of the class: CoreBreadcrumbsCompatibility{}

No Hooks.

Returns

array. Modified breadcrumb items.

Usage

// private - for code of main (parent) class only
$result = $this->replace_product_archive_breadcrumb_label( $items );
$items(array) (required)
Array of breadcrumb items from Core.

CoreBreadcrumbsCompatibility::replace_product_archive_breadcrumb_label() code 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;
}