WC_Breadcrumb::term_ancestors()protectedWC 1.0

Add crumbs for a term.

Method of the class: WC_Breadcrumb{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->term_ancestors( $term_id, $taxonomy );
$term_id(int) (required)
Term ID.
$taxonomy(string) (required)
Taxonomy.

WC_Breadcrumb::term_ancestors() code WC 9.7.1

protected function term_ancestors( $term_id, $taxonomy ) {
	$ancestors = get_ancestors( $term_id, $taxonomy );
	$ancestors = array_reverse( $ancestors );

	foreach ( $ancestors as $ancestor ) {
		$ancestor = get_term( $ancestor, $taxonomy );

		if ( ! is_wp_error( $ancestor ) && $ancestor ) {
			$this->add_crumb( $ancestor->name, get_term_link( $ancestor ) );
		}
	}
}