Automattic\WooCommerce\Blocks\BlockTypes

ProductCategories::getCount()protectedWC 1.0

Get the count, if displaying.

Method of the class: ProductCategories{}

No Hooks.

Return

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->getCount( $category, $attributes );
$category(object) (required)
Term object.
$attributes(array) (required)
Block attributes.
Default: empty array

ProductCategories::getCount() code WC 8.6.1

protected function getCount( $category, $attributes ) {
	if ( empty( $attributes['hasCount'] ) ) {
		return '';
	}

	if ( $attributes['isDropdown'] ) {
		return '(' . absint( $category->count ) . ')';
	}

	$screen_reader_text = sprintf(
		/* translators: %s number of products in cart. */
		_n( '%d product', '%d products', absint( $category->count ), 'woocommerce' ),
		absint( $category->count )
	);

	return '<span class="wc-block-product-categories-list-item-count">'
		. '<span aria-hidden="true">' . absint( $category->count ) . '</span>'
		. '<span class="screen-reader-text">' . esc_html( $screen_reader_text ) . '</span>'
	. '</span>';
}