Automattic\WooCommerce\Blocks

CoreBreadcrumbsCompatibility::replace_current_archive_breadcrumb_label │ private │ WC 1.0

Replace the current archive breadcrumb label.

Method of the class: CoreBreadcrumbsCompatibility{}

No Hooks.

Returns

array. Modified breadcrumb items.

Usage

// private - for code of main (parent) class only
$result = $this->replace_current_archive_breadcrumb_label( $items, $label, $archive_url );
$items(array) (required)
Array of breadcrumb items from Core.
$label(string) (required)
Replacement label.
$archive_url(string)
Archive URL.
Default: ''

CoreBreadcrumbsCompatibility::replace_current_archive_breadcrumb_label() code WC 11.2.1

private function replace_current_archive_breadcrumb_label( $items, $label, $archive_url = '' ) {
	$item_index = $this->get_breadcrumb_item_index_by_url( $items, $archive_url );

	if ( null === $item_index ) {
		$item_keys = array_keys( $items );

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

		$item_index = end( $item_keys );
		$paged      = (int) get_query_var( 'paged' );

		if ( $paged > 1 && count( $item_keys ) > 1 && isset( $items[ $item_index ]['label'] ) ) {
			$pagination_label = sprintf(
				/* translators: %s: page number */
				__( 'Page %s', 'default' ), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch -- Match the Core Breadcrumbs block pagination label.
				number_format_i18n( $paged )
			);

			if ( $pagination_label === (string) $items[ $item_index ]['label'] ) {
				$item_index = $item_keys[ count( $item_keys ) - 2 ];
			}
		}

		if ( ! empty( $items[ $item_index ]['url'] ) ) {
			return $items;
		}
	}

	return $this->replace_breadcrumb_label_at_index( $items, $item_index, $label );
}