Skip to content

Commit 96fb9a1

Browse files
committed
Small update to store availablity.
1 parent 83dd747 commit 96fb9a1

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

plugins/woocommerce/src/Internal/Abilities/StoreInfoAbility.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,31 @@ public static function execute_ability( array $input ): array {
9595

9696
// Include statistics if requested
9797
if ( ! empty( $input['include_stats'] ) ) {
98+
// Products use 'publish' status.
99+
$product_count = (int) wp_count_posts( 'product' )->publish;
100+
101+
// Orders using wc_get_orders for accurate counting
102+
$completed_orders = wc_get_orders( array(
103+
'status' => 'completed',
104+
'limit' => -1,
105+
'return' => 'ids',
106+
) );
107+
$completed_count = count( $completed_orders );
108+
109+
$order_breakdown = array(
110+
'completed' => $completed_count,
111+
);
112+
$order_count = $completed_count;
113+
114+
// Customers only.
115+
$users_counts = count_users();
116+
$customer_count = isset( $users_counts['avail_roles']['customer'] ) ? (int) $users_counts['avail_roles']['customer'] : 0;
117+
98118
$result['stats'] = array(
99-
'product_count' => wp_count_posts( 'product' )->publish,
100-
'order_count' => wp_count_posts( 'shop_order' )->publish,
101-
'customer_count' => count_users()['total_users'],
119+
'product_count' => $product_count,
120+
'order_count' => $order_count,
121+
'order_breakdown' => $order_breakdown,
122+
'customer_count' => $customer_count,
102123
);
103124
}
104125

0 commit comments

Comments
 (0)