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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-tracker.php
woocommerce / includes Last commit date
abstracts 9 months ago admin 9 months ago blocks 10 months ago cli 11 months ago customizer 11 months ago data-stores 9 months ago emails 9 months ago export 1 year ago gateways 9 months ago import 11 months ago integrations 2 years ago interfaces 1 year ago legacy 1 year ago libraries 1 year ago log-handlers 1 year ago payment-tokens 5 years ago product-usage 1 year ago queue 4 years ago react-admin 9 months ago rest-api 9 months ago shipping 1 year ago shortcodes 10 months ago theme-support 2 years ago tracks 10 months ago traits 5 years ago walkers 5 years ago wccom-site 9 months ago widgets 1 year ago class-wc-ajax.php 10 months ago class-wc-auth.php 1 year ago class-wc-autoloader.php 1 year ago class-wc-background-emailer.php 5 years ago class-wc-background-updater.php 5 years ago class-wc-brands-brand-settings-manager.php 1 year ago class-wc-brands-coupons.php 1 year ago class-wc-brands.php 9 months ago class-wc-breadcrumb.php 5 years ago class-wc-cache-helper.php 10 months ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 9 months ago class-wc-cart-totals.php 10 months ago class-wc-cart.php 9 months ago class-wc-checkout.php 1 year ago class-wc-cli.php 9 months ago class-wc-comments.php 9 months ago class-wc-countries.php 1 year ago class-wc-coupon.php 9 months ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 1 year ago class-wc-customer.php 9 months ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 2 years ago class-wc-deprecated-filter-hooks.php 3 years ago class-wc-discounts.php 10 months ago class-wc-download-handler.php 1 year ago class-wc-emails.php 10 months ago class-wc-embed.php 1 year ago class-wc-form-handler.php 9 months ago class-wc-frontend-scripts.php 9 months ago class-wc-geo-ip.php 11 months ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 1 year ago class-wc-https.php 2 years ago class-wc-install.php 9 months ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 1 year ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 2 years ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 1 year ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 1 year ago class-wc-order-item-shipping.php 1 year ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 1 year ago class-wc-order-query.php 4 years ago class-wc-order-refund.php 1 year ago class-wc-order.php 9 months ago class-wc-payment-gateways.php 9 months ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 9 months ago class-wc-post-types.php 1 year ago class-wc-privacy-background-process.php 1 year ago class-wc-privacy-erasers.php 9 months ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 11 months ago class-wc-product-attribute.php 4 years ago class-wc-product-download.php 2 years ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 1 year ago class-wc-product-grouped.php 10 months ago class-wc-product-query.php 1 year ago class-wc-product-simple.php 10 months ago class-wc-product-variable.php 10 months ago class-wc-product-variation.php 1 year ago class-wc-query.php 1 year ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 1 year ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 1 year ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 9 months ago class-wc-shipping-rate.php 11 months ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 1 year ago class-wc-shortcodes.php 1 year ago class-wc-structured-data.php 10 months ago class-wc-tax.php 10 months ago class-wc-template-loader.php 9 months ago class-wc-tracker.php 11 months ago class-wc-validation.php 2 years ago class-wc-webhook.php 1 year ago class-woocommerce.php 8 months ago wc-account-functions.php 9 months ago wc-attribute-functions.php 9 months ago wc-brands-functions.php 1 year ago wc-cart-functions.php 9 months ago wc-conditional-functions.php 10 months ago wc-core-functions.php 9 months ago wc-coupon-functions.php 9 months ago wc-deprecated-functions.php 9 months ago wc-formatting-functions.php 8 months ago wc-notice-functions.php 11 months ago wc-order-functions.php 9 months ago wc-order-item-functions.php 3 years ago wc-order-step-logger-functions.php 1 year ago wc-page-functions.php 1 year ago wc-product-functions.php 10 months ago wc-rest-functions.php 10 months ago wc-stock-functions.php 1 year ago wc-template-functions.php 9 months ago wc-template-hooks.php 9 months ago wc-term-functions.php 9 months ago wc-update-functions.php 8 months ago wc-user-functions.php 9 months ago wc-webhook-functions.php 1 year ago wc-widget-functions.php 5 years ago
class-wc-tracker.php
1534 lines
1 <?php
2 /**
3 * WooCommerce Tracker
4 *
5 * The WooCommerce tracker class adds functionality to track WooCommerce usage based on if the customer opted in.
6 * No personal information is tracked, only general WooCommerce settings, general product, order and user counts and admin email for discount code.
7 *
8 * @class WC_Tracker
9 * @since 2.3.0
10 * @package WooCommerce\Classes
11 */
12
13 use Automattic\Jetpack\Constants;
14 use Automattic\WooCommerce\Internal\Admin\EmailImprovements\EmailImprovements;
15 use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
16 use Automattic\WooCommerce\Utilities\{ FeaturesUtil, OrderUtil, PluginUtil };
17 use Automattic\WooCommerce\Internal\Utilities\BlocksUtil;
18 use Automattic\WooCommerce\Proxies\LegacyProxy;
19 use Automattic\WooCommerce\Blocks\Package;
20 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields;
21
22 defined( 'ABSPATH' ) || exit;
23
24 // phpcs:disable Squiz.Classes.ClassFileName.NoMatch, Squiz.Classes.ValidClassName.NotCamelCaps -- Backwards compatibility.
25 /**
26 * WooCommerce Tracker Class
27 */
28 class WC_Tracker {
29
30 // phpcs:enable
31 /**
32 * URL to the WooThemes Tracker API endpoint.
33 *
34 * @var string
35 */
36 private static $api_url = 'https://tracking.woocommerce.com/v1/';
37
38 /**
39 * Hook into cron event.
40 */
41 public static function init() { // phpcs:ignore WooCommerce.Functions.InternalInjectionMethod.MissingFinal, WooCommerce.Functions.InternalInjectionMethod.MissingInternalTag -- Not an injection.
42 add_action( 'woocommerce_tracker_send_event', array( __CLASS__, 'send_tracking_data' ) );
43 }
44
45 /**
46 * Decide whether to send tracking data or not.
47 *
48 * @param boolean $override Should override?.
49 */
50 public static function send_tracking_data( $override = false ) {
51 // Don't trigger this on AJAX Requests.
52 if ( Constants::is_true( 'DOING_AJAX' ) ) {
53 return;
54 }
55
56 /**
57 * Filter whether to send tracking data or not.
58 *
59 * @since 2.3.0
60 */
61 if ( ! apply_filters( 'woocommerce_tracker_send_override', $override ) ) {
62 // Send a maximum of once per week by default.
63 $last_send = self::get_last_send_time();
64 if ( $last_send && $last_send > apply_filters( 'woocommerce_tracker_last_send_interval', strtotime( '-1 week' ) ) ) { // phpcs:ignore
65 return;
66 }
67 } else {
68 // Make sure there is at least a 1 hour delay between override sends, we don't want duplicate calls due to double clicking links.
69 $last_send = self::get_last_send_time();
70 if ( $last_send && $last_send > strtotime( '-1 hours' ) ) {
71 return;
72 }
73 }
74
75 // Update time first before sending to ensure it is set.
76 update_option( 'woocommerce_tracker_last_send', time() );
77
78 $params = self::get_tracking_data();
79 wp_safe_remote_post(
80 self::$api_url,
81 array(
82 'method' => 'POST',
83 'timeout' => 45,
84 'redirection' => 5,
85 'httpversion' => '1.0',
86 'blocking' => false,
87 'headers' => array( 'user-agent' => 'WooCommerceTracker/' . md5( esc_url_raw( home_url( '/' ) ) ) . ';' ),
88 'body' => wp_json_encode( $params ),
89 'cookies' => array(),
90 )
91 );
92 }
93
94 /**
95 * Get the last time tracking data was sent.
96 *
97 * @return int|bool
98 */
99 private static function get_last_send_time() {
100 /**
101 * Filter the last time tracking data was sent.
102 *
103 * @since 2.3.0
104 */
105 return apply_filters( 'woocommerce_tracker_last_send_time', get_option( 'woocommerce_tracker_last_send', false ) );
106 }
107
108 /**
109 * Test whether this site is a staging site according to the Jetpack criteria.
110 *
111 * With Jetpack 8.1+, Jetpack::is_staging_site has been deprecated.
112 * \Automattic\Jetpack\Status::is_staging_site is the replacement.
113 * However, there are version of JP where \Automattic\Jetpack\Status exists, but does *not* contain is_staging_site method,
114 * so with those, code still needs to use the previous check as a fallback.
115 *
116 * After upgrading Jetpack Status to v3.3.2 is_staging_site is also deprecated and in_safe_mode is the new replacement.
117 * So we check this first of all.
118 *
119 * @return bool
120 */
121 private static function is_jetpack_staging_site() {
122 if ( class_exists( '\Automattic\Jetpack\Status' ) ) {
123
124 $jp_status = new \Automattic\Jetpack\Status();
125
126 if ( is_callable( array( $jp_status, 'in_safe_mode' ) ) ) {
127 return $jp_status->in_safe_mode();
128 } elseif ( is_callable( array( $jp_status, 'is_staging_site' ) ) ) {
129 // Preferred way of checking with Jetpack 8.1+.
130 return $jp_status->is_staging_site();
131 }
132 }
133
134 return ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_staging_site' ) && Jetpack::is_staging_site() );
135 }
136
137 /**
138 * Get all the tracking data.
139 *
140 * @return array
141 */
142 public static function get_tracking_data() {
143 $data = array();
144 $start_time = microtime( true );
145
146 // General site info.
147 $data['url'] = home_url();
148 $data['store_id'] = get_option( \WC_Install::STORE_ID_OPTION, null );
149 $data['blog_id'] = class_exists( 'Jetpack_Options' ) ? Jetpack_Options::get_option( 'id' ) : null;
150
151 /**
152 * Filter the admin email that's sent with data.
153 *
154 * @since 2.3.0
155 */
156 $data['email'] = apply_filters( 'woocommerce_tracker_admin_email', get_option( 'admin_email' ) );
157 $data['theme'] = self::get_theme_info();
158
159 // WordPress Info.
160 $data['wp'] = self::get_wordpress_info();
161
162 // Server Info.
163 $data['server'] = self::get_server_info();
164
165 // Plugin info.
166 $all_plugins = self::get_all_plugins();
167 $data['active_plugins'] = $all_plugins['active_plugins'];
168 $data['inactive_plugins'] = $all_plugins['inactive_plugins'];
169
170 // Jetpack & WooCommerce Connect.
171 $data['jetpack_version'] = Constants::is_defined( 'JETPACK__VERSION' ) ? Constants::get_constant( 'JETPACK__VERSION' ) : 'none';
172 $data['jetpack_connected'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_active' ) && Jetpack::is_active() ) ? 'yes' : 'no';
173 $data['jetpack_is_staging'] = self::is_jetpack_staging_site() ? 'yes' : 'no';
174 $data['connect_installed'] = class_exists( 'WC_Connect_Loader' ) ? 'yes' : 'no';
175 $data['connect_active'] = ( class_exists( 'WC_Connect_Loader' ) && wp_next_scheduled( 'wc_connect_fetch_service_schemas' ) ) ? 'yes' : 'no';
176 $data['helper_connected'] = self::get_helper_connected();
177
178 // Store count info.
179 $data['users'] = self::get_user_counts();
180 $data['products'] = self::get_product_counts();
181 $data['orders'] = self::get_orders();
182 $data['reviews'] = self::get_review_counts();
183 $data['categories'] = self::get_category_counts();
184 $data['brands'] = self::get_brands_counts();
185
186 // Get order snapshot.
187 $data['order_snapshot'] = self::get_order_snapshot();
188
189 // Payment gateway info.
190 $data['gateways'] = self::get_active_payment_gateways();
191
192 // WcPay settings info.
193 $data['wcpay_settings'] = self::get_wcpay_settings();
194
195 // Shipping method info.
196 $data['shipping_methods'] = self::get_active_shipping_methods();
197
198 // Features.
199 $data['enabled_features'] = self::get_enabled_features();
200
201 // Get all WooCommerce options info.
202 $data['settings'] = self::get_all_woocommerce_options_values();
203
204 // Template overrides.
205 $template_overrides = self::get_all_template_overrides();
206 $data['template_overrides'] = $template_overrides;
207
208 // Cart & checkout tech (blocks or shortcodes).
209 $data['cart_checkout'] = self::get_cart_checkout_info();
210
211 // Mini Cart block, which only exists since wp 5.9.
212 if ( version_compare( get_bloginfo( 'version' ), '5.9', '>=' ) ) {
213 $data['mini_cart_block'] = self::get_mini_cart_info();
214 }
215
216 /**
217 * Filter whether to disable admin tracking.
218 *
219 * @since 5.2.0
220 */
221 $data['wc_admin_disabled'] = apply_filters( 'woocommerce_admin_disabled', false ) ? 'yes' : 'no';
222
223 // Mobile info.
224 $data['wc_mobile_usage'] = self::get_woocommerce_mobile_usage();
225
226 // WC Tracker data.
227 $data['woocommerce_allow_tracking'] = get_option( 'woocommerce_allow_tracking', 'no' );
228 $data['woocommerce_allow_tracking_last_modified'] = get_option( 'woocommerce_allow_tracking_last_modified', 'unknown' );
229 $data['woocommerce_allow_tracking_first_optin'] = get_option( 'woocommerce_allow_tracking_first_optin', 'unknown' );
230
231 // Email improvements tracking data.
232 $data['email_improvements'] = self::get_email_improvements_info( $template_overrides );
233
234 // Store email usage.
235 $data['store_emails'] = self::get_store_emails();
236
237 /**
238 * Filter the data that's sent with the tracker.
239 *
240 * @since 2.3.0
241 */
242 $data = apply_filters( 'woocommerce_tracker_data', $data );
243
244 // Total seconds taken to generate snapshot (including filtered data).
245 $data['snapshot_generation_time'] = microtime( true ) - $start_time;
246
247 return $data;
248 }
249
250 /**
251 * Get the current theme info, theme name and version.
252 *
253 * @return array
254 */
255 public static function get_theme_info() {
256 $theme_data = wp_get_theme();
257 $theme_child_theme = wc_bool_to_string( is_child_theme() );
258 $theme_wc_support = wc_bool_to_string( current_theme_supports( 'woocommerce' ) );
259 $theme_is_block_theme = wc_bool_to_string( wp_is_block_theme() );
260
261 return array(
262 'name' => $theme_data->Name, // @phpcs:ignore
263 'version' => $theme_data->Version, // @phpcs:ignore
264 'child_theme' => $theme_child_theme,
265 'wc_support' => $theme_wc_support,
266 'block_theme' => $theme_is_block_theme,
267 );
268 }
269
270 /**
271 * Get WordPress related data.
272 *
273 * @return array
274 */
275 private static function get_wordpress_info() {
276 $wp_data = array();
277
278 $memory = wc_let_to_num( WP_MEMORY_LIMIT );
279
280 if ( function_exists( 'memory_get_usage' ) ) {
281 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- False positive.
282 $system_memory = wc_let_to_num( @ini_get( 'memory_limit' ) );
283 $memory = max( $memory, $system_memory );
284 }
285
286 // WordPress 5.5+ environment type specification.
287 // 'production' is the default in WP, thus using it as a default here, too.
288 $environment_type = 'production';
289 if ( function_exists( 'wp_get_environment_type' ) ) {
290 $environment_type = wp_get_environment_type();
291 }
292
293 $wp_data['memory_limit'] = size_format( $memory );
294 $wp_data['debug_mode'] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No';
295 $wp_data['locale'] = get_locale();
296 $wp_data['version'] = get_bloginfo( 'version' );
297 $wp_data['multisite'] = is_multisite() ? 'Yes' : 'No';
298 $wp_data['env_type'] = $environment_type;
299 $wp_data['dropins'] = array_keys( get_dropins() );
300
301 return $wp_data;
302 }
303
304 /**
305 * Get server related info.
306 *
307 * @return array
308 */
309 private static function get_server_info() {
310 $server_data = array();
311
312 if ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
313 $server_data['software'] = $_SERVER['SERVER_SOFTWARE']; // @phpcs:ignore
314 }
315
316 if ( function_exists( 'phpversion' ) ) {
317 $server_data['php_version'] = phpversion();
318 }
319
320 if ( function_exists( 'ini_get' ) ) {
321 $server_data['php_post_max_size'] = size_format( wc_let_to_num( ini_get( 'post_max_size' ) ) );
322 $server_data['php_time_limt'] = ini_get( 'max_execution_time' );
323 $server_data['php_max_input_vars'] = ini_get( 'max_input_vars' );
324 $server_data['php_suhosin'] = extension_loaded( 'suhosin' ) ? 'Yes' : 'No';
325 }
326
327 $database_version = wc_get_server_database_version();
328 $server_data['mysql_version'] = $database_version['number'];
329
330 $server_data['php_max_upload_size'] = size_format( wp_max_upload_size() );
331 $server_data['php_default_timezone'] = date_default_timezone_get();
332 $server_data['php_soap'] = class_exists( 'SoapClient' ) ? 'Yes' : 'No';
333 $server_data['php_fsockopen'] = function_exists( 'fsockopen' ) ? 'Yes' : 'No';
334 $server_data['php_curl'] = function_exists( 'curl_init' ) ? 'Yes' : 'No';
335
336 return $server_data;
337 }
338
339 /**
340 * Get all plugins grouped into activated or not.
341 *
342 * @return array
343 */
344 public static function get_all_plugins() {
345 // Ensure get_plugins function is loaded.
346 if ( ! function_exists( 'get_plugins' ) ) {
347 include ABSPATH . '/wp-admin/includes/plugin.php';
348 }
349
350 $plugins = wc_get_container()->get( LegacyProxy::class )->call_function( 'get_plugins' );
351 $active_plugins_keys = get_option( 'active_plugins', array() );
352 $active_plugins = array();
353
354 foreach ( $plugins as $k => $v ) {
355 // Take care of formatting the data how we want it.
356 $formatted = array();
357 $formatted['name'] = wp_strip_all_tags( $v['Name'] );
358 if ( isset( $v['Version'] ) ) {
359 $formatted['version'] = wp_strip_all_tags( $v['Version'] );
360 }
361 if ( isset( $v['Author'] ) ) {
362 $formatted['author'] = wp_strip_all_tags( $v['Author'] );
363 }
364 if ( isset( $v['Network'] ) ) {
365 $formatted['network'] = wp_strip_all_tags( $v['Network'] );
366 }
367 if ( isset( $v['PluginURI'] ) ) {
368 $formatted['plugin_uri'] = wp_strip_all_tags( $v['PluginURI'] );
369 }
370 $formatted['feature_compatibility'] = array();
371 if ( wc_get_container()->get( PluginUtil::class )->is_woocommerce_aware_plugin( $k ) ) {
372 $formatted['feature_compatibility'] = array_filter( FeaturesUtil::get_compatible_features_for_plugin( $k ) );
373 }
374 if ( in_array( $k, $active_plugins_keys, true ) ) {
375 // Remove active plugins from list so we can show active and inactive separately.
376 unset( $plugins[ $k ] );
377 $active_plugins[ $k ] = $formatted;
378 } else {
379 $plugins[ $k ] = $formatted;
380 }
381 }
382
383 return array(
384 'active_plugins' => $active_plugins,
385 'inactive_plugins' => $plugins,
386 );
387 }
388
389 /**
390 * Get the settings of WooCommerce Payments plugin
391 *
392 * @return array
393 */
394 private static function get_wcpay_settings() {
395 return get_option( 'woocommerce_woocommerce_payments_settings' );
396 }
397
398 /**
399 * Check to see if the helper is connected to WooCommerce.com
400 *
401 * @return string
402 */
403 private static function get_helper_connected() {
404 if ( class_exists( 'WC_Helper_Options' ) && is_callable( 'WC_Helper_Options::get' ) ) {
405 $authenticated = WC_Helper_Options::get( 'auth' );
406 } else {
407 $authenticated = '';
408 }
409 return ( ! empty( $authenticated ) ) ? 'yes' : 'no';
410 }
411
412
413 /**
414 * Get user totals based on user role.
415 *
416 * @return array
417 */
418 private static function get_user_counts() {
419 $user_count = array();
420 $user_count_data = count_users();
421 $user_count['total'] = $user_count_data['total_users'];
422
423 // Get user count based on user role.
424 foreach ( $user_count_data['avail_roles'] as $role => $count ) {
425 $user_count[ $role ] = $count;
426 }
427
428 return $user_count;
429 }
430
431 /**
432 * Get product totals based on product type.
433 *
434 * @return array
435 */
436 public static function get_product_counts() {
437 $product_count = array();
438 $product_count_data = wp_count_posts( 'product' );
439 $product_count['total'] = $product_count_data->publish;
440
441 $product_statuses = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
442 foreach ( $product_statuses as $product_status ) {
443 $product_count[ $product_status->name ] = $product_status->count;
444 }
445
446 return $product_count;
447 }
448
449 /**
450 * Get order counts.
451 *
452 * @return array
453 */
454 private static function get_order_counts() {
455 $order_count = array();
456 foreach ( wc_get_order_statuses() as $status_slug => $status_name ) {
457 $order_count[ $status_slug ] = wc_orders_count( $status_slug );
458 }
459 return $order_count;
460 }
461
462 /**
463 * Combine all order data.
464 *
465 * @return array
466 */
467 private static function get_orders() {
468 $order_dates = self::get_order_dates();
469 $order_counts = self::get_order_counts();
470 $order_totals = self::get_order_totals();
471 $order_gateways = self::get_orders_by_gateway();
472 $order_origin = self::get_orders_origins();
473
474 return array_merge( $order_dates, $order_counts, $order_totals, $order_gateways, $order_origin );
475 }
476
477 /**
478 * Get order totals.
479 *
480 * Keeping the internal statuses names as strings to avoid regression issues (not referencing Automattic\WooCommerce\Enums\OrderInternalStatus class).
481 *
482 * @since 5.4.0
483 * @return array
484 */
485 private static function get_order_totals() {
486 global $wpdb;
487
488 $orders_table = OrdersTableDataStore::get_orders_table_name();
489
490 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
491 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
492 $gross_total = $wpdb->get_var(
493 "
494 SELECT SUM(total_amount) AS 'gross_total'
495 FROM $orders_table
496 WHERE status in ('wc-completed', 'wc-refunded');
497 "
498 );
499 // phpcs:enable
500 } else {
501 $gross_total = $wpdb->get_var(
502 "
503 SELECT
504 SUM( order_meta.meta_value ) AS 'gross_total'
505 FROM {$wpdb->prefix}posts AS orders
506 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
507 WHERE order_meta.meta_key = '_order_total'
508 AND orders.post_status in ( 'wc-completed', 'wc-refunded' )
509 GROUP BY order_meta.meta_key
510 "
511 );
512 }
513
514 if ( is_null( $gross_total ) ) {
515 $gross_total = 0;
516 }
517
518 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
519 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
520 $processing_gross_total = $wpdb->get_var(
521 "
522 SELECT SUM(total_amount) AS 'gross_total'
523 FROM $orders_table
524 WHERE status = 'wc-processing';
525 "
526 );
527 // phpcs:enable
528 } else {
529 $processing_gross_total = $wpdb->get_var(
530 "
531 SELECT
532 SUM( order_meta.meta_value ) AS 'gross_total'
533 FROM {$wpdb->prefix}posts AS orders
534 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
535 WHERE order_meta.meta_key = '_order_total'
536 AND orders.post_status = 'wc-processing'
537 GROUP BY order_meta.meta_key
538 "
539 );
540 }
541
542 if ( is_null( $processing_gross_total ) ) {
543 $processing_gross_total = 0;
544 }
545
546 return array(
547 'gross' => $gross_total,
548 'processing_gross' => $processing_gross_total,
549 );
550 }
551
552 /**
553 * Get last order date.
554 *
555 * @return string
556 */
557 private static function get_order_dates() {
558 global $wpdb;
559
560 $orders_table = OrdersTableDataStore::get_orders_table_name();
561 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
562 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
563 $min_max = $wpdb->get_row(
564 "
565 SELECT
566 MIN( date_created_gmt ) as 'first', MAX( date_created_gmt ) as 'last'
567 FROM $orders_table
568 WHERE status = 'wc-completed';
569 ",
570 ARRAY_A
571 );
572 // phpcs:enable
573 } else {
574 $min_max = $wpdb->get_row(
575 "
576 SELECT
577 MIN( post_date_gmt ) as 'first', MAX( post_date_gmt ) as 'last'
578 FROM {$wpdb->prefix}posts
579 WHERE post_type = 'shop_order'
580 AND post_status = 'wc-completed'
581 ",
582 ARRAY_A
583 );
584 }
585
586 if ( is_null( $min_max ) ) {
587 $min_max = array(
588 'first' => '-',
589 'last' => '-',
590 );
591 }
592
593 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
594 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
595 $processing_min_max = $wpdb->get_row(
596 "
597 SELECT
598 MIN( date_created_gmt ) as 'processing_first', MAX( date_created_gmt ) as 'processing_last'
599 FROM $orders_table
600 WHERE status = 'wc-processing';
601 ",
602 ARRAY_A
603 );
604 // phpcs:enable
605 } else {
606 $processing_min_max = $wpdb->get_row(
607 "
608 SELECT
609 MIN( post_date_gmt ) as 'processing_first', MAX( post_date_gmt ) as 'processing_last'
610 FROM {$wpdb->prefix}posts
611 WHERE post_type = 'shop_order'
612 AND post_status = 'wc-processing'
613 ",
614 ARRAY_A
615 );
616 }
617
618 if ( is_null( $processing_min_max ) ) {
619 $processing_min_max = array(
620 'processing_first' => '-',
621 'processing_last' => '-',
622 );
623 }
624
625 return array_merge( $min_max, $processing_min_max );
626 }
627
628 /**
629 * Extract the group key for an associative array of objects which have unique ids in the key.
630 * A 'group_key' property is introduced in the object.
631 * For example, two objects with keys like 'WooDataPay ** #123' and 'WooDataPay ** #78' would
632 * both have a group_key of 'WooDataPay **' after this function call.
633 *
634 * @param array $objects The array of objects that need to be grouped.
635 * @param string $default_key The property that will be the default group_key.
636 * @return array Contains the objects with a group_key property.
637 */
638 private static function extract_group_key( $objects, $default_key ) {
639 $keys = array_keys( $objects );
640
641 // Sort keys by length and then by characters within the same length keys.
642 usort(
643 $keys,
644 function ( $a, $b ) {
645 if ( strlen( $a ) === strlen( $b ) ) {
646 return strcmp( $a, $b );
647 }
648 return ( strlen( $a ) < strlen( $b ) ) ? -1 : 1;
649 }
650 );
651
652 // Look for common tokens in every pair of adjacent keys.
653 $prev = '';
654 foreach ( $keys as $key ) {
655 if ( $prev ) {
656 $comm_tokens = array();
657
658 // Tokenize the current and previous gateway names.
659 $curr_tokens = preg_split( '/[ :,\-_]+/', $key );
660 $prev_tokens = preg_split( '/[ :,\-_]+/', $prev );
661
662 $len_curr = is_array( $curr_tokens ) ? count( $curr_tokens ) : 0;
663 $len_prev = is_array( $prev_tokens ) ? count( $prev_tokens ) : 0;
664
665 $index_unique = -1;
666 // Gather the common tokens.
667 // Let us allow for the unique reference id to be anywhere in the name.
668 for ( $i = 0; $i < $len_curr && $i < $len_prev; $i++ ) {
669 if ( $curr_tokens[ $i ] === $prev_tokens[ $i ] ) {
670 $comm_tokens[] = $curr_tokens[ $i ];
671 } elseif ( preg_match( '/\d/', $curr_tokens[ $i ] ) && preg_match( '/\d/', $prev_tokens[ $i ] ) ) {
672 $index_unique = $i;
673 }
674 }
675
676 // If only one token is different, and those tokens contain digits, then that could be the unique id.
677 if ( $len_curr - count( $comm_tokens ) <= 1 && count( $comm_tokens ) > 0 && $index_unique > -1 ) {
678 $objects[ $key ]->group_key = implode( ' ', $comm_tokens );
679 $objects[ $prev ]->group_key = implode( ' ', $comm_tokens );
680 } else {
681 $objects[ $key ]->group_key = $objects[ $key ]->$default_key;
682 }
683 } else {
684 $objects[ $key ]->group_key = $objects[ $key ]->$default_key;
685 }
686 $prev = $key;
687 }
688 return $objects;
689 }
690
691 /**
692 * Get order details by gateway.
693 *
694 * @return array
695 */
696 private static function get_orders_by_gateway() {
697 global $wpdb;
698
699 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
700 $orders_table = OrdersTableDataStore::get_orders_table_name();
701 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
702 $orders_and_gateway_details = $wpdb->get_results(
703 "
704 SELECT IFNULL(payment_method, '') AS gateway, currency AS currency, SUM( total_amount ) AS totals, count( id ) AS counts
705 FROM $orders_table
706 WHERE status IN ( 'wc-completed', 'wc-processing', 'wc-refunded' )
707 GROUP BY gateway, currency;
708 "
709 );
710 // phpcs:enable
711 } else {
712 $orders_and_gateway_details = $wpdb->get_results(
713 "
714 SELECT
715 gateway, currency, SUM(total) AS totals, COUNT(order_id) AS counts
716 FROM (
717 SELECT
718 orders.id AS order_id,
719 IFNULL(MAX(CASE WHEN meta_key = '_payment_method' THEN meta_value END), '') gateway,
720 MAX(CASE WHEN meta_key = '_order_total' THEN meta_value END) total,
721 MAX(CASE WHEN meta_key = '_order_currency' THEN meta_value END) currency
722 FROM
723 {$wpdb->prefix}posts orders
724 LEFT JOIN
725 {$wpdb->prefix}postmeta order_meta ON order_meta.post_id = orders.id
726 WHERE orders.post_type = 'shop_order'
727 AND orders.post_status in ( 'wc-completed', 'wc-processing', 'wc-refunded' )
728 AND meta_key in( '_payment_method','_order_total','_order_currency')
729 GROUP BY orders.id
730 ) order_gateways
731 GROUP BY gateway, currency
732 "
733 );
734 }
735
736 $orders_by_gateway_currency = array();
737
738 // The associative array that is created as the result of array_reduce is passed to extract_group_key()
739 // This function has the logic that will remove specific transaction identifiers that may sometimes be part of a
740 // payment method. For example, two payments methods like 'WooDataPay ** #123' and 'WooDataPay ** #78' would
741 // both have the same group_key 'WooDataPay **'.
742 $orders_by_gateway = self::extract_group_key(
743 // Convert into an associative array with a combination of currency and gateway as key.
744 array_reduce(
745 $orders_and_gateway_details,
746 function ( $result, $item ) {
747 $item->gateway = preg_replace( '/\s+/', ' ', $item->gateway ?? '' );
748
749 // Introduce currency as a prefix for the key.
750 $key = $item->currency . '==' . $item->gateway;
751
752 $result[ $key ] = $item;
753 return $result;
754 },
755 array()
756 ),
757 'gateway'
758 );
759
760 // Aggregate using group_key.
761 foreach ( $orders_by_gateway as $orders_details ) {
762 $gkey = $orders_details->group_key;
763
764 // Remove currency as prefix of key for backward compatibility.
765 if ( str_contains( $gkey, '==' ) ) {
766 $tokens = preg_split( '/==/', $gkey );
767 $key = $tokens[1];
768 } else {
769 $key = $gkey;
770 }
771
772 $key = str_replace( array( 'payment method', 'payment gateway', 'gateway' ), '', strtolower( $key ) );
773 $key = trim( preg_replace( '/[: ,#*\-_]+/', ' ', $key ) );
774
775 // Add currency as postfix of gateway for backward compatibility.
776 $key = 'gateway_' . $key . '_' . $orders_details->currency;
777 $count_key = $key . '_count';
778 $total_key = $key . '_total';
779
780 if ( array_key_exists( $count_key, $orders_by_gateway_currency ) || array_key_exists( $total_key, $orders_by_gateway_currency ) ) {
781 $orders_by_gateway_currency[ $count_key ] = $orders_by_gateway_currency[ $count_key ] + $orders_details->counts;
782 $orders_by_gateway_currency[ $total_key ] = $orders_by_gateway_currency[ $total_key ] + $orders_details->totals;
783 } else {
784 $orders_by_gateway_currency[ $count_key ] = $orders_details->counts;
785 $orders_by_gateway_currency[ $total_key ] = $orders_details->totals;
786 }
787 }
788
789 return $orders_by_gateway_currency;
790 }
791
792 /**
793 * Get orders origin details.
794 *
795 * @return array
796 */
797 private static function get_orders_origins() {
798 global $wpdb;
799
800 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
801 $op_table_name = OrdersTableDataStore::get_operational_data_table_name();
802 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
803 $orders_origin = $wpdb->get_results(
804 "
805 SELECT IFNULL(created_via, '') as origin, COUNT( order_id ) as count
806 FROM $op_table_name
807 GROUP BY origin;
808 "
809 );
810 // phpcs:enable
811 } else {
812 $orders_origin = $wpdb->get_results(
813 "
814 SELECT
815 IFNULL(meta_value, '') as origin, COUNT( DISTINCT ( orders.id ) ) as count
816 FROM
817 $wpdb->posts orders
818 LEFT JOIN
819 $wpdb->postmeta order_meta ON order_meta.post_id = orders.id
820 WHERE
821 meta_key = '_created_via'
822 GROUP BY
823 origin;
824 "
825 );
826 }
827
828 // The associative array that is created as the result of array_reduce is passed to extract_group_key()
829 // This function has the logic that will remove specific identifiers that may sometimes be part of an origin.
830 // For example, two origins like 'Import #123' and 'Import ** #78' would both have a group_key 'Import **'.
831 $orders_and_origins = self::extract_group_key(
832 // Convert into an associative array with the origin as key.
833 array_reduce(
834 $orders_origin,
835 function ( $result, $item ) {
836 $key = $item->origin;
837
838 $result[ $key ] = $item;
839 return $result;
840 },
841 array()
842 ),
843 'origin'
844 );
845
846 $orders_by_origin = array();
847
848 // Aggregate using group_key.
849 foreach ( $orders_and_origins as $origin ) {
850 $key = strtolower( $origin->group_key ?? '' );
851
852 if ( array_key_exists( $key, $orders_by_origin ) ) {
853 $orders_by_origin[ $key ] = $orders_by_origin[ $key ] + (int) $origin->count;
854 } else {
855 $orders_by_origin[ $key ] = (int) $origin->count;
856 }
857 }
858
859 return array( 'created_via' => $orders_by_origin );
860 }
861
862 /**
863 * Get review counts for different statuses.
864 *
865 * @return array
866 */
867 private static function get_review_counts() {
868 global $wpdb;
869 $review_count = array( 'total' => 0 );
870 $status_map = array(
871 '0' => 'pending',
872 '1' => 'approved',
873 'trash' => 'trash',
874 'spam' => 'spam',
875 );
876 $counts = $wpdb->get_results(
877 "
878 SELECT comment_approved, COUNT(*) AS num_reviews
879 FROM {$wpdb->comments}
880 WHERE comment_type = 'review'
881 GROUP BY comment_approved
882 ",
883 ARRAY_A
884 );
885
886 if ( ! $counts ) {
887 return $review_count;
888 }
889
890 foreach ( $counts as $count ) {
891 $status = $count['comment_approved'];
892 if ( array_key_exists( $status, $status_map ) ) {
893 $review_count[ $status_map[ $status ] ] = $count['num_reviews'];
894 }
895 $review_count['total'] += $count['num_reviews'];
896 }
897
898 return $review_count;
899 }
900
901 /**
902 * Get the number of product categories.
903 *
904 * @return int
905 */
906 private static function get_category_counts() {
907 return wp_count_terms( 'product_cat' );
908 }
909
910 /**
911 * Get the number of product brands.
912 *
913 * @return int
914 */
915 private static function get_brands_counts() {
916 if ( ! taxonomy_exists( 'product_brand' ) ) {
917 return 0;
918 }
919 return wp_count_terms( 'product_brand' );
920 }
921
922 /**
923 * Get a list of all active payment gateways.
924 *
925 * @return array
926 */
927 private static function get_active_payment_gateways() {
928 $active_gateways = array();
929 $gateways = WC()->payment_gateways->payment_gateways();
930 foreach ( $gateways as $id => $gateway ) {
931 if ( isset( $gateway->enabled ) && 'yes' === $gateway->enabled ) {
932 $active_gateways[ $id ] = array(
933 'title' => $gateway->title,
934 'supports' => $gateway->supports,
935 );
936 }
937 }
938
939 return $active_gateways;
940 }
941
942
943 /**
944 * Get a list of all active shipping methods.
945 *
946 * @return array
947 */
948 private static function get_active_shipping_methods() {
949 $active_methods = array();
950 $shipping_methods = WC()->shipping()->get_shipping_methods();
951 foreach ( $shipping_methods as $id => $shipping_method ) {
952 if ( isset( $shipping_method->enabled ) && 'yes' === $shipping_method->enabled ) {
953 $active_methods[ $id ] = array(
954 'title' => $shipping_method->title,
955 'tax_status' => $shipping_method->tax_status,
956 );
957 }
958 }
959
960 return $active_methods;
961 }
962
963 /**
964 * Get an array of slugs for WC features that are enabled on the site.
965 *
966 * @return string[]
967 */
968 private static function get_enabled_features() {
969 $all_features = FeaturesUtil::get_features( true, true );
970 $enabled_features = array_filter(
971 $all_features,
972 function ( $feature ) {
973 return $feature['is_enabled'];
974 }
975 );
976
977 return array_keys( $enabled_features );
978 }
979
980 /**
981 * Get all options starting with woocommerce_ prefix.
982 *
983 * @return array
984 */
985 private static function get_all_woocommerce_options_values() {
986 return array(
987 'version' => WC()->version,
988 'currency' => get_woocommerce_currency(),
989 'base_location' => WC()->countries->get_base_country(),
990 'base_state' => WC()->countries->get_base_state(),
991 'base_postcode' => WC()->countries->get_base_postcode(),
992 'selling_locations' => WC()->countries->get_allowed_countries(),
993 'api_enabled' => get_option( 'woocommerce_api_enabled', 'no' ),
994 'weight_unit' => get_option( 'woocommerce_weight_unit' ),
995 'dimension_unit' => get_option( 'woocommerce_dimension_unit' ),
996 'download_method' => get_option( 'woocommerce_file_download_method' ),
997 'download_require_login' => get_option( 'woocommerce_downloads_require_login' ),
998 'calc_taxes' => get_option( 'woocommerce_calc_taxes' ),
999 'coupons_enabled' => get_option( 'woocommerce_enable_coupons' ),
1000 'guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
1001 'delayed_account_creation' => get_option( 'woocommerce_enable_delayed_account_creation' ),
1002 'checkout_login_reminder' => get_option( 'woocommerce_enable_checkout_login_reminder' ),
1003 'secure_checkout' => get_option( 'woocommerce_force_ssl_checkout' ),
1004 'enable_signup_and_login_from_checkout' => get_option( 'woocommerce_enable_signup_and_login_from_checkout' ),
1005 'enable_myaccount_registration' => get_option( 'woocommerce_enable_myaccount_registration' ),
1006 'registration_generate_username' => get_option( 'woocommerce_registration_generate_username' ),
1007 'registration_generate_password' => get_option( 'woocommerce_registration_generate_password' ),
1008 'hpos_sync_enabled' => get_option( 'woocommerce_custom_orders_table_data_sync_enabled' ),
1009 'hpos_cot_authoritative' => get_option( 'woocommerce_custom_orders_table_enabled' ),
1010 'hpos_transactions_enabled' => get_option( 'woocommerce_use_db_transactions_for_custom_orders_table_data_sync' ),
1011 'hpos_transactions_level' => get_option( 'woocommerce_db_transactions_isolation_level_for_custom_orders_table_data_sync' ),
1012 'show_marketplace_suggestions' => get_option( 'woocommerce_show_marketplace_suggestions' ),
1013 'admin_install_timestamp' => get_option( 'woocommerce_admin_install_timestamp' ),
1014 );
1015 }
1016
1017 /**
1018 * Look for any template override and return filenames.
1019 *
1020 * @return array
1021 */
1022 public static function get_all_template_overrides() {
1023 $override_data = array();
1024 /**
1025 * Filter the paths to scan for template overrides.
1026 *
1027 * @since 2.3.0
1028 */
1029 $template_paths = (array) apply_filters( 'woocommerce_template_overrides_scan_paths', array( 'WooCommerce' => WC()->plugin_path() . '/templates/' ) );
1030 $scanned_files = array();
1031
1032 require_once WC()->plugin_path() . '/includes/admin/class-wc-admin-status.php';
1033
1034 foreach ( $template_paths as $plugin_name => $template_path ) {
1035 $scanned_files[ $plugin_name ] = WC_Admin_Status::scan_template_files( $template_path );
1036 }
1037
1038 foreach ( $scanned_files as $plugin_name => $files ) {
1039 foreach ( $files as $file ) {
1040 if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
1041 $theme_file = get_stylesheet_directory() . '/' . $file;
1042 } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) {
1043 $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file;
1044 } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
1045 $theme_file = get_template_directory() . '/' . $file;
1046 } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) {
1047 $theme_file = get_template_directory() . '/' . WC()->template_path() . $file;
1048 } else {
1049 $theme_file = false;
1050 }
1051
1052 if ( false !== $theme_file ) {
1053 $override_data[] = basename( $theme_file );
1054 }
1055 }
1056 }
1057 return $override_data;
1058 }
1059
1060 /**
1061 * Search a specific post for text content.
1062 *
1063 * @param integer $post_id The id of the post to search.
1064 * @param string $text The text to search for.
1065 * @return string 'Yes' if post contains $text (otherwise 'No').
1066 */
1067 public static function post_contains_text( $post_id, $text ) {
1068 global $wpdb;
1069
1070 // Search for the text anywhere in the post.
1071 $wildcarded = "%{$text}%";
1072
1073 $result = $wpdb->get_var(
1074 $wpdb->prepare(
1075 "
1076 SELECT COUNT( * ) FROM {$wpdb->prefix}posts
1077 WHERE ID=%d
1078 AND {$wpdb->prefix}posts.post_content LIKE %s
1079 ",
1080 array( $post_id, $wildcarded )
1081 )
1082 );
1083
1084 return ( '0' !== $result ) ? 'Yes' : 'No';
1085 }
1086
1087
1088 /**
1089 * Get tracker data for a specific block type on a woocommerce page.
1090 *
1091 * @param string $block_name The name (id) of a block, e.g. `woocommerce/cart`.
1092 * @param string $woo_page_name The woo page to search, e.g. `cart`.
1093 * @return array Associative array of tracker data with keys:
1094 * - page_contains_block
1095 * - block_attributes
1096 */
1097 public static function get_block_tracker_data( $block_name, $woo_page_name ) {
1098 $blocks = WC_Blocks_Utils::get_blocks_from_page( $block_name, $woo_page_name );
1099
1100 $block_present = false;
1101 $attributes = array();
1102 if ( $blocks && count( $blocks ) ) {
1103 // Return any customised attributes from the first block.
1104 $block_present = true;
1105 $attributes = $blocks[0]['attrs'];
1106 }
1107
1108 return array(
1109 'page_contains_block' => $block_present ? 'Yes' : 'No',
1110 'block_attributes' => $attributes,
1111 );
1112 }
1113
1114 /**
1115 * Get tracker data for a pickup location method.
1116 *
1117 * @return array Associative array of tracker data with keys:
1118 * - pickup_location_enabled
1119 * - pickup_locations_count
1120 */
1121 public static function get_pickup_location_data() {
1122 $pickup_location_enabled = false;
1123 $pickup_location_pickup_locations = get_option( 'pickup_location_pickup_locations', array() );
1124 $pickup_locations_count = is_countable( $pickup_location_pickup_locations ) ? count( $pickup_location_pickup_locations ) : 0;
1125
1126 // Get the available shipping methods.
1127 $shipping_methods = WC()->shipping()->get_shipping_methods();
1128
1129 // Check if the desired shipping method is enabled.
1130 if ( isset( $shipping_methods['pickup_location'] ) && $shipping_methods['pickup_location']->is_enabled() ) {
1131 $pickup_location_enabled = true;
1132 }
1133
1134 return array(
1135 'pickup_location_enabled' => $pickup_location_enabled,
1136 'pickup_locations_count' => $pickup_locations_count,
1137 );
1138 }
1139
1140 /**
1141 * Get tracker data for additional fields on the checkout page.
1142 *
1143 * @return array Array of fields count and names.
1144 */
1145 public static function get_checkout_additional_fields_data() {
1146 $additional_fields_controller = Package::container()->get( CheckoutFields::class );
1147
1148 return array(
1149 'fields_count' => count( $additional_fields_controller->get_additional_fields() ),
1150 'fields_names' => array_keys( $additional_fields_controller->get_additional_fields() ),
1151 );
1152 }
1153 /**
1154 * Get info about the cart & checkout pages.
1155 *
1156 * @return array
1157 */
1158 public static function get_cart_checkout_info() {
1159 $cart_page_id = wc_get_page_id( 'cart' );
1160 $checkout_page_id = wc_get_page_id( 'checkout' );
1161
1162 $cart_block_data = self::get_block_tracker_data( 'woocommerce/cart', 'cart' );
1163 $checkout_block_data = self::get_block_tracker_data( 'woocommerce/checkout', 'checkout' );
1164
1165 $pickup_location_data = self::get_pickup_location_data();
1166
1167 $additional_fields_data = self::get_checkout_additional_fields_data();
1168
1169 return array(
1170 'cart_page_contains_cart_shortcode' => self::post_contains_text(
1171 $cart_page_id,
1172 '[woocommerce_cart]'
1173 ),
1174 'checkout_page_contains_checkout_shortcode' => self::post_contains_text(
1175 $checkout_page_id,
1176 '[woocommerce_checkout]'
1177 ),
1178
1179 'cart_page_contains_cart_block' => $cart_block_data['page_contains_block'],
1180 'cart_block_attributes' => $cart_block_data['block_attributes'],
1181 'checkout_page_contains_checkout_block' => $checkout_block_data['page_contains_block'],
1182 'checkout_block_attributes' => $checkout_block_data['block_attributes'],
1183 'pickup_location' => $pickup_location_data,
1184 'additional_fields' => $additional_fields_data,
1185 );
1186 }
1187
1188 /**
1189 * Get info about the Mini Cart Block.
1190 *
1191 * @return array
1192 */
1193 private static function get_mini_cart_info() {
1194 $mini_cart_block_name = 'woocommerce/mini-cart';
1195 $mini_cart_block_data = wp_is_block_theme() ? BlocksUtil::get_block_from_template_part( $mini_cart_block_name, 'header' ) : BlocksUtil::get_blocks_from_widget_area( $mini_cart_block_name );
1196 return array(
1197 'mini_cart_used' => empty( $mini_cart_block_data[0] ) ? 'No' : 'Yes',
1198 'mini_cart_block_attributes' => empty( $mini_cart_block_data[0] ) ? array() : $mini_cart_block_data[0]['attrs'],
1199 );
1200 }
1201
1202 /**
1203 * Get info about WooCommerce Mobile App usage
1204 *
1205 * @return array
1206 */
1207 public static function get_woocommerce_mobile_usage() {
1208 return get_option( 'woocommerce_mobile_app_usage' );
1209 }
1210
1211 /**
1212 * Map legacy order meta keys to a column name.
1213 *
1214 * @param string $meta_key Legacy meta key name.
1215 * @return string Mapped column name.
1216 */
1217 private static function map_legacy_meta_key_name( $meta_key ) {
1218 switch ( $meta_key ) {
1219 case '_order_currency':
1220 return 'currency';
1221 case '_order_total':
1222 return 'total_amount';
1223 case '_payment_method':
1224 return 'payment_method';
1225 case '_payment_method_title':
1226 return 'payment_method_title';
1227 case '_recorded_sales':
1228 return 'recorded_sales';
1229 case '_order_version':
1230 return 'woocommerce_version';
1231 default:
1232 return $meta_key;
1233 }
1234 }
1235
1236 /**
1237 * Fetch main order data.
1238 *
1239 * @param string $sort_order Date sort order (ASC or DESC).
1240 * @param integer $limit Limit the amount of orders to return (default 20).
1241 * @return array Found orders indexed by ID.
1242 */
1243 private static function get_order_data( $sort_order = 'ASC', $limit = 20 ) {
1244 global $wpdb;
1245
1246 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
1247 $order_table_name = OrdersTableDataStore::get_orders_table_name();
1248
1249 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1250 $orders = $wpdb->get_results(
1251 "SELECT
1252 id,
1253 row_number() OVER (ORDER BY date_created_gmt) AS order_rank,
1254 date_created_gmt AS order_created_at,
1255 date_updated_gmt AS order_updated_at,
1256 currency,
1257 total_amount,
1258 payment_method,
1259 payment_method_title
1260 FROM $order_table_name
1261 WHERE
1262 type = 'shop_order'
1263 AND status IN ('wc-completed', 'wc-refunded')
1264 ORDER BY date_created_gmt $sort_order
1265 LIMIT $limit;",
1266 ARRAY_A
1267 );
1268 // phpcs:enable
1269 } else {
1270 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1271 $orders = $wpdb->get_results(
1272 "SELECT
1273 ID AS id,
1274 row_number() OVER (ORDER BY post_date_gmt) AS order_rank,
1275 post_date_gmt AS order_created_at,
1276 post_modified_gmt AS order_updated_at
1277 FROM $wpdb->posts
1278 WHERE
1279 post_type = 'shop_order'
1280 AND post_status IN ('wc-completed', 'wc-refunded')
1281 ORDER BY post_date_gmt $sort_order
1282 LIMIT $limit;",
1283 ARRAY_A
1284 );
1285 // phpcs:enable
1286 }
1287
1288 return array_column( $orders, null, 'id' );
1289 }
1290
1291 /**
1292 * Fetch additional data for a specific set of orders.
1293 *
1294 * @param array $order_ids List of order ID's to fetch data for.
1295 * @return array Additional data, indexed by order ID.
1296 */
1297 private static function get_additional_order_data( $order_ids ) {
1298 global $wpdb;
1299
1300 if ( empty( $order_ids ) || ! is_array( $order_ids ) ) {
1301 return array();
1302 }
1303 $joined_ids = implode( ',', $order_ids );
1304 $additional_data = array();
1305
1306 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
1307 $op_table_name = OrdersTableDataStore::get_operational_data_table_name();
1308
1309 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1310 $data = $wpdb->get_results(
1311 "SELECT order_id, woocommerce_version, recorded_sales
1312 FROM $op_table_name
1313 WHERE order_id IN ($joined_ids)",
1314 ARRAY_A
1315 );
1316 // phpcs:enable
1317
1318 foreach ( $data as $row ) {
1319 $additional_data[ $row['order_id'] ] = array(
1320 'woocommerce_version' => $row['woocommerce_version'],
1321 'recorded_sales' => $row['recorded_sales'] ? 'yes' : 'no',
1322 );
1323 }
1324 } else {
1325 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1326 $data = $wpdb->get_results(
1327 "SELECT post_id AS order_id, meta_key, meta_value
1328 FROM $wpdb->postmeta
1329 WHERE
1330 meta_key IN (
1331 '_order_currency',
1332 '_order_total',
1333 '_payment_method',
1334 '_payment_method_title',
1335 '_recorded_sales',
1336 '_order_version'
1337 )
1338 AND post_id IN ($joined_ids)
1339 ",
1340 ARRAY_A
1341 );
1342 // phpcs:enable
1343
1344 foreach ( $data as $row ) {
1345 $meta_key = self::map_legacy_meta_key_name( $row['meta_key'] );
1346 $additional_data[ $row['order_id'] ][ $meta_key ] = $row['meta_value'];
1347 }
1348 }
1349
1350 return $additional_data;
1351 }
1352
1353 /**
1354 * Fetch refund data for a specific set of orders.
1355 *
1356 * @param array $order_ids List of order ID's to fetch data for.
1357 * @return array Refund data, indexed by order ID.
1358 */
1359 private static function get_refund_order_data( $order_ids ) {
1360 global $wpdb;
1361
1362 if ( empty( $order_ids ) || ! is_array( $order_ids ) ) {
1363 return array();
1364 }
1365 $joined_ids = implode( ',', $order_ids );
1366 $refund_data = array();
1367
1368 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
1369 $order_table_name = OrdersTableDataStore::get_orders_table_name();
1370
1371 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1372 $data = $wpdb->get_results(
1373 "SELECT
1374 parent_order_id AS order_id,
1375 SUM(total_amount) AS refund_amount
1376 FROM $order_table_name
1377 WHERE
1378 type = 'shop_order_refund'
1379 AND status = 'wc-completed'
1380 AND parent_order_id IN ($joined_ids)
1381 GROUP BY parent_order_id",
1382 ARRAY_A
1383 );
1384 // phpcs:enable
1385 } else {
1386 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1387 $data = $wpdb->get_results(
1388 "SELECT
1389 refunds.post_parent AS order_id,
1390 SUM(amount.meta_value) AS refund_amount
1391 FROM $wpdb->posts AS refunds
1392 LEFT JOIN $wpdb->postmeta AS amount ON amount.post_id = refunds.ID AND amount.meta_key = '_order_total'
1393 WHERE
1394 refunds.post_type = 'shop_order_refund'
1395 AND refunds.post_status = 'wc-completed'
1396 AND refunds.post_parent IN ($joined_ids)
1397 GROUP BY refunds.post_parent",
1398 ARRAY_A
1399 );
1400 // phpcs:enable
1401 }
1402
1403 foreach ( $data as $row ) {
1404 $refund_data[ $row['order_id'] ] = array(
1405 'refund_amount' => $row['refund_amount'],
1406 );
1407 }
1408
1409 return $refund_data;
1410 }
1411
1412 /**
1413 * Get a snapshot of the first 20 orders and the last 20 orders.
1414 *
1415 * @return array
1416 */
1417 private static function get_order_snapshot() {
1418 $first_20 = self::get_order_data( 'ASC', 20 );
1419 $last_20 = self::get_order_data( 'DESC', 20 );
1420 $order_ids = array_unique( array_merge( array_keys( $first_20 ), array_keys( $last_20 ) ) );
1421
1422 foreach ( self::get_additional_order_data( $order_ids ) as $order_id => $data ) {
1423 if ( isset( $first_20[ $order_id ] ) ) {
1424 $first_20[ $order_id ] = array_merge( $first_20[ $order_id ], $data );
1425 }
1426 if ( isset( $last_20[ $order_id ] ) ) {
1427 $last_20[ $order_id ] = array_merge( $last_20[ $order_id ], $data );
1428 }
1429 }
1430
1431 foreach ( self::get_refund_order_data( $order_ids ) as $order_id => $data ) {
1432 if ( isset( $first_20[ $order_id ] ) ) {
1433 $first_20[ $order_id ] = array_merge( $first_20[ $order_id ], $data );
1434 }
1435 if ( isset( $last_20[ $order_id ] ) ) {
1436 $last_20[ $order_id ] = array_merge( $last_20[ $order_id ], $data );
1437 }
1438 }
1439
1440 return array(
1441 'first_20_orders' => $first_20,
1442 'last_20_orders' => $last_20,
1443 );
1444 }
1445
1446 /**
1447 * Get email improvements tracking data.
1448 *
1449 * @param array $template_overrides Template overrides.
1450 * @return array Email improvements tracking data.
1451 */
1452 private static function get_email_improvements_info( $template_overrides ) {
1453 $core_email_counts = self::get_core_email_status_counts();
1454 $core_email_overrides = self::get_core_email_overrides( $template_overrides );
1455
1456 return array(
1457 'enabled' => get_option( 'woocommerce_feature_email_improvements_enabled', 'no' ),
1458 'default_enabled' => get_option( 'woocommerce_email_improvements_default_enabled', 'no' ),
1459 'existing_store_enabled' => get_option( 'woocommerce_email_improvements_existing_store_enabled', 'no' ),
1460 'auto_sync_enabled' => get_option( 'woocommerce_email_auto_sync_with_theme', 'no' ),
1461 'first_enabled_at' => get_option( 'woocommerce_email_improvements_first_enabled_at', null ),
1462 'last_enabled_at' => get_option( 'woocommerce_email_improvements_last_enabled_at', null ),
1463 'enabled_count' => get_option( 'woocommerce_email_improvements_enabled_count', 0 ),
1464 'first_disabled_at' => get_option( 'woocommerce_email_improvements_first_disabled_at', null ),
1465 'last_disabled_at' => get_option( 'woocommerce_email_improvements_last_disabled_at', null ),
1466 'disabled_count' => get_option( 'woocommerce_email_improvements_disabled_count', 0 ),
1467 'core_email_enabled_count' => $core_email_counts['enabled'],
1468 'core_email_disabled_count' => $core_email_counts['disabled'],
1469 'core_email_overrides_count' => $core_email_overrides['count'],
1470 'core_email_overrides_templates' => array_keys( $core_email_overrides['templates'] ),
1471 );
1472 }
1473
1474 /**
1475 * Get store email usage.
1476 *
1477 * @return array Email usage.
1478 */
1479 private static function get_store_emails() {
1480 $enabled_emails = EmailImprovements::get_enabled_emails();
1481 $disabled_emails = EmailImprovements::get_disabled_emails();
1482 $enabled_or_manual_emails_with_cc_or_bcc = EmailImprovements::get_enabled_or_manual_emails_with_cc_or_bcc();
1483
1484 return array(
1485 'enabled_emails' => $enabled_emails,
1486 'enabled_emails_count' => count( $enabled_emails ),
1487 'disabled_emails' => $disabled_emails,
1488 'disabled_emails_count' => count( $disabled_emails ),
1489 'enabled_or_manual_emails_with_cc' => $enabled_or_manual_emails_with_cc_or_bcc['ccs'],
1490 'enabled_or_manual_emails_with_cc_count' => count( $enabled_or_manual_emails_with_cc_or_bcc['ccs'] ),
1491 'enabled_or_manual_emails_with_bcc' => $enabled_or_manual_emails_with_cc_or_bcc['bccs'],
1492 'enabled_or_manual_emails_with_bcc_count' => count( $enabled_or_manual_emails_with_cc_or_bcc['bccs'] ),
1493 );
1494 }
1495
1496 /**
1497 * Get counts of enabled and disabled core emails.
1498 *
1499 * @return array Array with counts of enabled and disabled emails.
1500 */
1501 private static function get_core_email_status_counts() {
1502 $core_emails = EmailImprovements::get_core_emails();
1503 $enabled = 0;
1504 $disabled = 0;
1505
1506 foreach ( $core_emails as $email ) {
1507 if ( $email->is_enabled() ) {
1508 ++$enabled;
1509 } else {
1510 ++$disabled;
1511 }
1512 }
1513
1514 return array(
1515 'enabled' => $enabled,
1516 'disabled' => $disabled,
1517 );
1518 }
1519
1520 /**
1521 * Check if any core emails are being overridden by a template override.
1522 *
1523 * @param array $template_overrides Template overrides.
1524 * @return array Array with count of core email overrides and the templates that are overriden.
1525 */
1526 public static function get_core_email_overrides( $template_overrides ): array {
1527 $email_template_overrides = EmailImprovements::get_core_email_overrides( $template_overrides );
1528 return array(
1529 'count' => count( $email_template_overrides ),
1530 'templates' => $email_template_overrides,
1531 );
1532 }
1533 }
1534