Automattic\WooCommerce\Blocks

CoreBreadcrumbsCompatibility::prepend_my_account_page_to_endpoint_breadcrumbs │ private │ WC 1.0

Prepend the My Account page to account endpoint breadcrumbs.

Method of the class: CoreBreadcrumbsCompatibility{}

No Hooks.

Returns

array. Modified breadcrumb items.

Usage

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

CoreBreadcrumbsCompatibility::prepend_my_account_page_to_endpoint_breadcrumbs() code WC 11.1.2

private function prepend_my_account_page_to_endpoint_breadcrumbs( $items ) {
	if ( ! is_wc_endpoint_url() || ! is_account_page() ) {
		return $items;
	}

	$my_account_page = $this->get_woocommerce_page_post( 'myaccount' );
	$my_account_url  = $my_account_page ? get_permalink( $my_account_page ) : '';

	if ( ! $my_account_page || ! $my_account_url ) {
		return $items;
	}

	$woocommerce = WC();

	if ( $woocommerce->query instanceof \WC_Query ) {
		$endpoint       = $woocommerce->query->get_current_endpoint();
		$action         = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Used only to select the breadcrumb label.
		$endpoint_title = $endpoint ? $woocommerce->query->get_endpoint_title( $endpoint, $action ) : '';

		if ( $endpoint_title ) {
			$items = $this->replace_current_archive_breadcrumb_label( $items, $endpoint_title );
		}
	}

	return $this->insert_parent_breadcrumb_item_if_missing_url(
		$items,
		array(
			'label' => $my_account_page->post_title,
			'url'   => $my_account_url,
		)
	);
}