WC_Breadcrumb::add_crumbs_single()protectedWC 1.0

Single post trail.

Метод класса: WC_Breadcrumb{}

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->add_crumbs_single( $post_id, $permalink );
$post_id(int)
Post ID.
$permalink(строка)
Post permalink.
По умолчанию: ''

Код WC_Breadcrumb::add_crumbs_single() WC 8.7.0

protected function add_crumbs_single( $post_id = 0, $permalink = '' ) {
	if ( ! $post_id ) {
		global $post;
	} else {
		$post = get_post( $post_id ); // WPCS: override ok.
	}

	if ( ! $permalink ) {
		$permalink = get_permalink( $post );
	}

	if ( 'product' === get_post_type( $post ) ) {
		$this->prepend_shop_page();

		$terms = wc_get_product_terms(
			$post->ID,
			'product_cat',
			apply_filters(
				'woocommerce_breadcrumb_product_terms_args',
				array(
					'orderby' => 'parent',
					'order'   => 'DESC',
				)
			)
		);

		if ( $terms ) {
			$main_term = apply_filters( 'woocommerce_breadcrumb_main_term', $terms[0], $terms );
			$this->term_ancestors( $main_term->term_id, 'product_cat' );
			$this->add_crumb( $main_term->name, get_term_link( $main_term ) );
		}
	} elseif ( 'post' !== get_post_type( $post ) ) {
		$post_type = get_post_type_object( get_post_type( $post ) );

		if ( ! empty( $post_type->has_archive ) ) {
			$this->add_crumb( $post_type->labels->singular_name, get_post_type_archive_link( get_post_type( $post ) ) );
		}
	} else {
		$cat = current( get_the_category( $post ) );
		if ( $cat ) {
			$this->term_ancestors( $cat->term_id, 'category' );
			$this->add_crumb( $cat->name, get_term_link( $cat ) );
		}
	}

	$this->add_crumb( get_the_title( $post ), $permalink );
}