Commit 60ada59df14 for woocommerce
commit 60ada59df147aef458f2579fdaa5d86e0166e9a2
Author: Luigi Teschio <gigitux@gmail.com>
Date: Wed Aug 12 16:35:48 2026 +0200
Deprecate product brand recount methods (#67657)
* Deprecate product brand recount methods
* Add changelog entry for product brand recount deprecations
* Correct brand recount deprecation version
* Delegate deprecated brand recount methods
* fix baseline
diff --git a/plugins/woocommerce/changelog/deprecate-brand-recount-methods b/plugins/woocommerce/changelog/deprecate-brand-recount-methods
new file mode 100644
index 00000000000..92e6ff8dfed
--- /dev/null
+++ b/plugins/woocommerce/changelog/deprecate-brand-recount-methods
@@ -0,0 +1,4 @@
+Significance: minor
+Type: update
+
+Deprecate the WC_Brands recount methods in favor of the shared term recount functions.
diff --git a/plugins/woocommerce/includes/class-wc-brands.php b/plugins/woocommerce/includes/class-wc-brands.php
index 4162033ac2b..c2496549b1c 100644
--- a/plugins/woocommerce/includes/class-wc-brands.php
+++ b/plugins/woocommerce/includes/class-wc-brands.php
@@ -82,51 +82,23 @@ class WC_Brands {
/**
* Recount the brands after the stock amount changes.
*
+ * @deprecated 11.2.0 Use wc_recount_after_stock_change() instead.
+ *
* @param int $product_id Product ID.
*/
public function recount_after_stock_change( $product_id ) {
- if ( 'yes' !== get_option( 'woocommerce_hide_out_of_stock_items' ) || empty( $product_id ) ) {
- return;
- }
-
- $product_terms = get_the_terms( $product_id, 'product_brand' );
-
- if ( ! $product_terms ) {
- return;
- }
-
- if ( wp_defer_term_counting() ) {
- // When deferring term counts, we're using the built in handling of `wp_update_term_count()` to deal with the deferring
- // and, though, this will cause both the standard and stock based counts to be rerun, it is still more efficient
- // in cases where deferred term counting was warranted.
- $product_terms = get_the_terms( $product_id, 'product_brand' );
- if ( is_array( $product_terms ) ) {
- wp_update_term_count( array_column( $product_terms, 'term_taxonomy_id' ), 'product_brand' );
- }
- return;
- }
-
- $product_brands = array();
-
- foreach ( $product_terms as $term ) {
- $product_brands[ $term->term_id ] = $term->parent;
- }
-
- _wc_term_recount( $product_brands, get_taxonomy( 'product_brand' ), false, false );
+ wc_deprecated_function( __METHOD__, '11.2.0', 'wc_recount_after_stock_change()' );
+ wc_recount_after_stock_change( $product_id );
}
/**
* Recount all brands.
+ *
+ * @deprecated 11.2.0 Use wc_recount_all_terms() instead.
*/
public function recount_all_brands() {
- $product_brands = get_terms(
- array(
- 'taxonomy' => 'product_brand',
- 'hide_empty' => false,
- 'fields' => 'id=>parent',
- )
- );
- _wc_term_recount( $product_brands, get_taxonomy( 'product_brand' ), true, false );
+ wc_deprecated_function( __METHOD__, '11.2.0', 'wc_recount_all_terms()' );
+ wc_recount_all_terms();
}
/**
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 0f0608f5c73..63661fff008 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -9186,12 +9186,6 @@ parameters:
count: 1
path: includes/class-wc-brands.php
- -
- message: '#^Argument of an invalid type array\<WP_Term\>\|WP_Error supplied for foreach, only iterables are supported\.$#'
- identifier: foreach.nonIterable
- count: 1
- path: includes/class-wc-brands.php
-
-
message: '#^Argument of an invalid type array\<int, WP_Term\>\|WP_Error supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
@@ -9402,24 +9396,12 @@ parameters:
count: 1
path: includes/class-wc-brands.php
- -
- message: '#^Parameter \#1 \$terms of function _wc_term_recount expects array, array\<int, int\>\|WP_Error given\.$#'
- identifier: argument.type
- count: 1
- path: includes/class-wc-brands.php
-
-
message: '#^Parameter \#2 \$str of function explode expects string, array\|string given\.$#'
identifier: argument.type
count: 2
path: includes/class-wc-brands.php
- -
- message: '#^Parameter \#2 \$taxonomy of function _wc_term_recount expects WP_Taxonomy, WP_Taxonomy\|false given\.$#'
- identifier: argument.type
- count: 2
- path: includes/class-wc-brands.php
-
-
message: '#^Cannot access property \$ID on WP_Post\|null\.$#'
identifier: property.nonObject