Only count published products in productCount (#50503)

* Only count published products in productCount

* Add changelog

* Fix lint

* Fix lint
This commit is contained in:
Fernando Marichal 2024-08-13 12:28:55 -03:00 committed by GitHub
parent 7a20d626d3
commit 5922b42577
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Only count published products in productCount

View File

@ -450,14 +450,16 @@ abstract class AbstractBlock {
'wordCountType' => _x( 'words', 'Word count type. Do not translate!', 'woocommerce' ),
];
if ( is_admin() && ! WC()->is_rest_api_request() ) {
$wc_blocks_config = array_merge(
$product_counts = wp_count_posts( 'product' );
$published_products = isset( $product_counts->publish ) ? $product_counts->publish : 0;
$wc_blocks_config = array_merge(
$wc_blocks_config,
[
// Note that while we don't have a consolidated way of doing feature-flagging
// we are borrowing from the WC Admin Features implementation. Also note we cannot
// use the wcAdminFeatures global because it's not always enqueued in the context of blocks.
'experimentalBlocksEnabled' => Features::is_enabled( 'experimental-blocks' ),
'productCount' => array_sum( (array) wp_count_posts( 'product' ) ),
'productCount' => $published_products,
]
);
}