Commit ad52d2d3927 for woocommerce
commit ad52d2d3927e71161ed3ef9329ea117b6f0a67ce
Author: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
Date: Mon Oct 12 18:02:18 2026 +0200
Add styling supports to Product Results Count (#69606)
* Add styling supports to Product Results Count
* Add changelog entry for Product Results Count styling
* Preserve Product Results Count font size compatibility class
* Explain legacy font size class compatibility
* Shorten font size compatibility comment
* Remove redundant Product Results Count block class
diff --git a/docs/block-development/reference/block-references.md b/docs/block-development/reference/block-references.md
index 3600f2f362b..dea5c1372c0 100644
--- a/docs/block-development/reference/block-references.md
+++ b/docs/block-development/reference/block-references.md
@@ -1402,7 +1402,7 @@ Display the number of products on the archive page or search result page.
- **Name:** woocommerce/product-results-count
- **Category:** woocommerce
-- **Supports:** color (text, ~~background~~), interactivity (clientNavigation), typography (fontSize)
+- **Supports:** color (background, gradients, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, textAlign)
## Product Reviews - woocommerce/product-reviews
diff --git a/plugins/woocommerce/changelog/add-product-results-count-supports b/plugins/woocommerce/changelog/add-product-results-count-supports
new file mode 100644
index 00000000000..0ff5cad2f94
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-product-results-count-supports
@@ -0,0 +1,4 @@
+Significance: minor
+Type: enhancement
+
+Customize product results counts with alignment, typography, spacing, background colors, and gradients.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-results-count/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-results-count/block.json
index c11f534d97d..b1c7b5b12ed 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-results-count/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-results-count/block.json
@@ -10,10 +10,20 @@
},
"color": {
"text": true,
- "background": false
+ "background": true,
+ "gradients": true
+ },
+ "spacing": {
+ "margin": true,
+ "padding": true
},
"typography": {
- "fontSize": true
+ "fontSize": true,
+ "textAlign": true,
+ "__experimentalFontFamily": true,
+ "__experimentalFontWeight": true,
+ "__experimentalFontStyle": true,
+ "__experimentalLetterSpacing": true
}
},
"usesContext": [ "queryId" ],
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index fbf318cdfe8..292d4002820 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -51507,30 +51507,6 @@ parameters:
count: 1
path: src/Blocks/BlockTypes/ProductRatingStars.php
- -
- message: '#^Access to property \$context on an unknown class Automattic\\WooCommerce\\Blocks\\BlockTypes\\WP_Block\.$#'
- identifier: class.notFound
- count: 2
- path: src/Blocks/BlockTypes/ProductResultsCount.php
-
- -
- message: '#^Parameter \#1 \$html of class WP_HTML_Tag_Processor constructor expects string, string\|false given\.$#'
- identifier: argument.type
- count: 1
- path: src/Blocks/BlockTypes/ProductResultsCount.php
-
- -
- message: '#^Parameter \#1 \$query of method WP_HTML_Tag_Processor\:\:next_tag\(\) expects array\{tag_name\?\: string\|null, match_offset\?\: int\|null, class_name\?\: string\|null, tag_closers\?\: string\|null\}\|null, ''div'' given\.$#'
- identifier: argument.type
- count: 1
- path: src/Blocks/BlockTypes/ProductResultsCount.php
-
- -
- message: '#^Parameter \$block of method Automattic\\WooCommerce\\Blocks\\BlockTypes\\ProductResultsCount\:\:render\(\) has invalid type Automattic\\WooCommerce\\Blocks\\BlockTypes\\WP_Block\.$#'
- identifier: class.notFound
- count: 1
- path: src/Blocks/BlockTypes/ProductResultsCount.php
-
-
message: '#^Method Automattic\\WooCommerce\\Blocks\\BlockTypes\\ProductSKU\:\:get_block_type_uses_context\(\) has no return type specified\.$#'
identifier: missingType.return
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductResultsCount.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductResultsCount.php
index a1252b07270..bc6877f0a61 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductResultsCount.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductResultsCount.php
@@ -1,9 +1,8 @@
<?php
+declare( strict_types = 1 );
namespace Automattic\WooCommerce\Blocks\BlockTypes;
-use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
-
/**
* ProductResultsCount class.
*/
@@ -28,41 +27,32 @@ class ProductResultsCount extends AbstractBlock {
/**
* Render the block.
*
- * @param array $attributes Block attributes.
- * @param string $content Block content.
- * @param WP_Block $block Block instance.
+ * @param array $attributes Block attributes.
+ * @param string $content Block content.
+ * @param \WP_Block $block Block instance.
*
* @return string Rendered block output.
*/
protected function render( $attributes, $content, $block ) {
// Buffer the result count and use it as the block's frontend content.
ob_start();
- echo '<div>';
woocommerce_result_count();
- echo '</div>';
$product_results_count = ob_get_clean();
- $p = new \WP_HTML_Tag_Processor( $product_results_count );
+ $classes = 'woocommerce wc-block-product-results-count';
+ if ( ! empty( $attributes['fontSize'] ) ) {
+ // Preserve the legacy class for backward compatibility.
+ $classes .= ' has-font-size';
+ }
- // Advance to the wrapper and add the attributes necessary for the block.
- $p->next_tag( 'div' );
- $parsed_style_attributes = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
- $classes = array_merge(
- explode( ' ', $parsed_style_attributes['classes'] ),
+ $wrapper_attributes = get_block_wrapper_attributes(
array(
- 'woocommerce',
- 'wc-block-product-results-count',
- 'wp-block-woocommerce-product-results-count',
- ),
- );
- $p->set_attribute( 'class', implode( ' ', $classes ) );
- $p->set_attribute( 'style', $parsed_style_attributes['styles'] );
- $p->set_attribute( 'data-wp-interactive', $this->get_full_block_name() );
- $p->set_attribute(
- 'data-wp-router-region',
- 'wc-product-results-count-' . ( isset( $block->context['queryId'] ) ? $block->context['queryId'] : 0 )
+ 'class' => $classes,
+ 'data-wp-interactive' => $this->get_full_block_name(),
+ 'data-wp-router-region' => 'wc-product-results-count-' . ( $block->context['queryId'] ?? 0 ),
+ )
);
- return $p->get_updated_html();
+ return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $product_results_count );
}
}