Automattic\WooCommerce\Blocks\BlockTypes\Reviews

ProductReviewsTitle::get_reviews_titleprivateWC 1.0

Get the reviews title.

Method of the class: ProductReviewsTitle{}

No Hooks.

Returns

String.

Usage

// private - for code of main (parent) class only
$result = $this->get_reviews_title( $attributes, $product );
$attributes(array) (required)
Block attributes.
$product(WC_Product) (required)
Product instance.

ProductReviewsTitle::get_reviews_title() code WC 10.7.0

private function get_reviews_title( $attributes, $product ) {
	$show_product_title = ! empty( $attributes['showProductTitle'] ) && $attributes['showProductTitle'];
	$show_reviews_count = ! empty( $attributes['showReviewsCount'] ) && $attributes['showReviewsCount'];
	$reviews_count      = $product->get_review_count();

	if ( $show_reviews_count && $show_product_title ) {
		return 1 === $reviews_count
			/* translators: %s: Product title. */
			? sprintf( __( 'One review for %s', 'woocommerce' ), $product->get_title() )
			: sprintf(
				/* translators: 1: Number of reviews, 2: Product title. */
				_n(
					'%1$s review for %2$s',
					'%1$s reviews for %2$s',
					$reviews_count,
					'woocommerce'
				),
				number_format_i18n( $reviews_count ),
				$product->get_title()
			);
	}

	if ( ! $show_reviews_count && $show_product_title ) {
		return 1 === $reviews_count
			/* translators: %s: Product title. */
			? sprintf( __( 'Review for %s', 'woocommerce' ), $product->get_title() )
			: sprintf(
				/* translators: %s: Product title. */
				__( 'Reviews for %s', 'woocommerce' ),
				$product->get_title()
			);
	}

	if ( $show_reviews_count && ! $show_product_title ) {
		return 1 === $reviews_count
			/* translators: %s: Number of reviews. */
			? __( 'One review', 'woocommerce' )
			: sprintf(
				/* translators: %s: Number of reviews. */
				_n( '%s review', '%s reviews', $reviews_count, 'woocommerce' ),
				number_format_i18n( $reviews_count )
			);
	}

	if ( 1 === $reviews_count ) {
		return __( 'Review', 'woocommerce' );
	}

	return __( 'Reviews', 'woocommerce' );
}