WC_Breadcrumb::add_crumbs_pageprotectedWC 1.0

Page trail.

Method of the class: WC_Breadcrumb{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->add_crumbs_page();

WC_Breadcrumb::add_crumbs_page() code WC 10.8.1

protected function add_crumbs_page() {
	global $post;

	if ( $post->post_parent ) {
		$parent_crumbs = array();
		$parent_id     = $post->post_parent;

		while ( $parent_id ) {
			$page            = get_post( $parent_id );
			$parent_id       = $page->post_parent;
			$parent_crumbs[] = array( get_the_title( $page->ID ), get_permalink( $page->ID ) );
		}

		$parent_crumbs = array_reverse( $parent_crumbs );

		foreach ( $parent_crumbs as $crumb ) {
			$this->add_crumb( $crumb[0], $crumb[1] );
		}
	}

	// On WC endpoints, get_the_title() returns the endpoint title (via wc_page_endpoint_title filter).
	// Use post_title directly to avoid duplicates like "Orders / Orders" instead of "My Account / Orders".
	$permalink = get_permalink();
	if ( is_wc_endpoint_url() ) {
		$this->add_crumb( $post->post_title, $permalink ? $permalink : '' );
	} else {
		$this->add_crumb( get_the_title(), $permalink ? $permalink : '' );
	}

	$this->endpoint_trail();
}