ProductResultsCount.php
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
class ProductResultsCount extends AbstractBlock {
protected $block_name = 'product-results-count';
protected function get_block_type_script( $key = null ) {
return null;
}
protected function render( $attributes, $content, $block ) {
ob_start();
echo '<div>';
woocommerce_result_count();
echo '</div>';
$product_results_count = ob_get_clean();
$p = new \WP_HTML_Tag_Processor( $product_results_count );
$p->next_tag( 'div' );
$parsed_style_attributes = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
$classes = array_merge(
explode( ' ', $parsed_style_attributes['classes'] ),
array(
'woocommerce',
'wc-block-product-results-count',
'wp-block-woocommerce-product-results-count',
),
isset( $attributes['className'] ) ? array( $attributes['className'] ) : array(),
);
$p->set_attribute( 'class', implode( ' ', $classes ) );
$p->set_attribute( 'style', $parsed_style_attributes['styles'] );
$p->set_attribute(
'data-wc-navigation-id',
'wc-product-results-count-' . ( isset( $block->context['queryId'] ) ? $block->context['queryId'] : 0 )
);
return $p->get_updated_html();
}
}