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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 1 year ago admin 1 year ago blocks 5 years ago cli 2 years ago customizer 2 years ago data-stores 2 years ago emails 2 years ago export 2 years ago gateways 2 years ago import 2 years ago integrations 2 years ago interfaces 3 years ago legacy 2 years ago libraries 3 years ago log-handlers 2 years ago payment-tokens 5 years ago queue 4 years ago react-admin 1 year ago rest-api 1 year ago shipping 1 year ago shortcodes 2 years ago theme-support 2 years ago tracks 2 years ago traits 5 years ago walkers 5 years ago wccom-site 2 years ago widgets 2 years ago class-wc-ajax.php 2 years ago class-wc-auth.php 2 years 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-breadcrumb.php 5 years ago class-wc-cache-helper.php 3 years ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 2 years ago class-wc-cart-totals.php 2 years ago class-wc-cart.php 2 years ago class-wc-checkout.php 2 years ago class-wc-cli.php 2 years ago class-wc-comments.php 3 years ago class-wc-countries.php 1 year ago class-wc-coupon.php 2 years ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 4 years ago class-wc-customer.php 2 years 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 2 years ago class-wc-download-handler.php 3 years ago class-wc-emails.php 2 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 2 years ago class-wc-frontend-scripts.php 2 years ago class-wc-geo-ip.php 2 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 3 years ago class-wc-https.php 2 years ago class-wc-install.php 1 year ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 2 years 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 2 years ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 2 years ago class-wc-order-item-shipping.php 2 years ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 2 years ago class-wc-order-query.php 4 years ago class-wc-order-refund.php 2 years ago class-wc-order.php 2 years ago class-wc-payment-gateways.php 2 years ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 3 years ago class-wc-post-types.php 2 years ago class-wc-privacy-background-process.php 5 years ago class-wc-privacy-erasers.php 4 years ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 2 years ago class-wc-product-attribute.php 4 years ago class-wc-product-download.php 2 years ago class-wc-product-external.php 5 years ago class-wc-product-factory.php 2 years ago class-wc-product-grouped.php 8 years ago class-wc-product-query.php 5 years ago class-wc-product-simple.php 2 years ago class-wc-product-variable.php 2 years ago class-wc-product-variation.php 4 years ago class-wc-query.php 2 years ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 2 years ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 3 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 2 years ago class-wc-shipping-rate.php 3 years ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 4 years ago class-wc-shortcodes.php 2 years ago class-wc-structured-data.php 2 years ago class-wc-tax.php 2 years ago class-wc-template-loader.php 2 years ago class-wc-tracker.php 2 years ago class-wc-validation.php 2 years ago class-wc-webhook.php 2 years ago class-woocommerce.php 3 months ago wc-account-functions.php 2 years ago wc-attribute-functions.php 3 years ago wc-cart-functions.php 2 years ago wc-conditional-functions.php 2 years ago wc-core-functions.php 2 years ago wc-coupon-functions.php 3 years ago wc-deprecated-functions.php 2 years ago wc-formatting-functions.php 2 years ago wc-notice-functions.php 2 years ago wc-order-functions.php 2 years ago wc-order-item-functions.php 3 years ago wc-page-functions.php 2 years ago wc-product-functions.php 2 years ago wc-rest-functions.php 2 years ago wc-stock-functions.php 3 years ago wc-template-functions.php 2 years ago wc-template-hooks.php 2 years ago wc-term-functions.php 3 years ago wc-update-functions.php 2 years ago wc-user-functions.php 2 years ago wc-webhook-functions.php 2 years ago wc-widget-functions.php 5 years ago
class-wc-tracker.php
1167 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\DataStores\Orders\OrdersTableDataStore;
15 use Automattic\WooCommerce\Utilities\{ FeaturesUtil, OrderUtil, PluginUtil };
16 use Automattic\WooCommerce\Internal\Utilities\BlocksUtil;
17 use Automattic\WooCommerce\Proxies\LegacyProxy;
18 use Automattic\WooCommerce\Blocks\Package;
19 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields;
20
21 defined( 'ABSPATH' ) || exit;
22
23 // phpcs:disable Squiz.Classes.ClassFileName.NoMatch, Squiz.Classes.ValidClassName.NotCamelCaps -- Backwards compatibility.
24 /**
25 * WooCommerce Tracker Class
26 */
27 class WC_Tracker {
28
29 // phpcs:enable
30 /**
31 * URL to the WooThemes Tracker API endpoint.
32 *
33 * @var string
34 */
35 private static $api_url = 'https://tracking.woocommerce.com/v1/';
36
37 /**
38 * Hook into cron event.
39 */
40 public static function init() { // phpcs:ignore WooCommerce.Functions.InternalInjectionMethod.MissingFinal, WooCommerce.Functions.InternalInjectionMethod.MissingInternalTag -- Not an injection.
41 add_action( 'woocommerce_tracker_send_event', array( __CLASS__, 'send_tracking_data' ) );
42 }
43
44 /**
45 * Decide whether to send tracking data or not.
46 *
47 * @param boolean $override Should override?.
48 */
49 public static function send_tracking_data( $override = false ) {
50 // Don't trigger this on AJAX Requests.
51 if ( Constants::is_true( 'DOING_AJAX' ) ) {
52 return;
53 }
54
55 /**
56 * Filter whether to send tracking data or not.
57 *
58 * @since 2.3.0
59 */
60 if ( ! apply_filters( 'woocommerce_tracker_send_override', $override ) ) {
61 // Send a maximum of once per week by default.
62 $last_send = self::get_last_send_time();
63 if ( $last_send && $last_send > apply_filters( 'woocommerce_tracker_last_send_interval', strtotime( '-1 week' ) ) ) { // phpcs:ignore
64 return;
65 }
66 } else {
67 // Make sure there is at least a 1 hour delay between override sends, we don't want duplicate calls due to double clicking links.
68 $last_send = self::get_last_send_time();
69 if ( $last_send && $last_send > strtotime( '-1 hours' ) ) {
70 return;
71 }
72 }
73
74 // Update time first before sending to ensure it is set.
75 update_option( 'woocommerce_tracker_last_send', time() );
76
77 $params = self::get_tracking_data();
78 wp_safe_remote_post(
79 self::$api_url,
80 array(
81 'method' => 'POST',
82 'timeout' => 45,
83 'redirection' => 5,
84 'httpversion' => '1.0',
85 'blocking' => false,
86 'headers' => array( 'user-agent' => 'WooCommerceTracker/' . md5( esc_url_raw( home_url( '/' ) ) ) . ';' ),
87 'body' => wp_json_encode( $params ),
88 'cookies' => array(),
89 )
90 );
91 }
92
93 /**
94 * Get the last time tracking data was sent.
95 *
96 * @return int|bool
97 */
98 private static function get_last_send_time() {
99 /**
100 * Filter the last time tracking data was sent.
101 *
102 * @since 2.3.0
103 */
104 return apply_filters( 'woocommerce_tracker_last_send_time', get_option( 'woocommerce_tracker_last_send', false ) );
105 }
106
107 /**
108 * Test whether this site is a staging site according to the Jetpack criteria.
109 *
110 * With Jetpack 8.1+, Jetpack::is_staging_site has been deprecated.
111 * \Automattic\Jetpack\Status::is_staging_site is the replacement.
112 * However, there are version of JP where \Automattic\Jetpack\Status exists, but does *not* contain is_staging_site method,
113 * so with those, code still needs to use the previous check as a fallback.
114 *
115 * @return bool
116 */
117 private static function is_jetpack_staging_site() {
118 if ( class_exists( '\Automattic\Jetpack\Status' ) ) {
119 // Preferred way of checking with Jetpack 8.1+.
120 $jp_status = new \Automattic\Jetpack\Status();
121 if ( is_callable( array( $jp_status, 'is_staging_site' ) ) ) {
122 return $jp_status->is_staging_site();
123 }
124 }
125
126 return ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_staging_site' ) && Jetpack::is_staging_site() );
127 }
128
129 /**
130 * Get all the tracking data.
131 *
132 * @return array
133 */
134 public static function get_tracking_data() {
135 $data = array();
136
137 // General site info.
138 $data['url'] = home_url();
139 $data['store_id'] = get_option( \WC_Install::STORE_ID_OPTION, null );
140 $data['blog_id'] = class_exists( 'Jetpack_Options' ) ? Jetpack_Options::get_option( 'id' ) : null;
141
142 /**
143 * Filter the admin email that's sent with data.
144 *
145 * @since 2.3.0
146 */
147 $data['email'] = apply_filters( 'woocommerce_tracker_admin_email', get_option( 'admin_email' ) );
148 $data['theme'] = self::get_theme_info();
149
150 // WordPress Info.
151 $data['wp'] = self::get_wordpress_info();
152
153 // Server Info.
154 $data['server'] = self::get_server_info();
155
156 // Plugin info.
157 $all_plugins = self::get_all_plugins();
158 $data['active_plugins'] = $all_plugins['active_plugins'];
159 $data['inactive_plugins'] = $all_plugins['inactive_plugins'];
160
161 // Jetpack & WooCommerce Connect.
162 $data['jetpack_version'] = Constants::is_defined( 'JETPACK__VERSION' ) ? Constants::get_constant( 'JETPACK__VERSION' ) : 'none';
163 $data['jetpack_connected'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_active' ) && Jetpack::is_active() ) ? 'yes' : 'no';
164 $data['jetpack_is_staging'] = self::is_jetpack_staging_site() ? 'yes' : 'no';
165 $data['connect_installed'] = class_exists( 'WC_Connect_Loader' ) ? 'yes' : 'no';
166 $data['connect_active'] = ( class_exists( 'WC_Connect_Loader' ) && wp_next_scheduled( 'wc_connect_fetch_service_schemas' ) ) ? 'yes' : 'no';
167 $data['helper_connected'] = self::get_helper_connected();
168
169 // Store count info.
170 $data['users'] = self::get_user_counts();
171 $data['products'] = self::get_product_counts();
172 $data['orders'] = self::get_orders();
173 $data['reviews'] = self::get_review_counts();
174 $data['categories'] = self::get_category_counts();
175
176 // Payment gateway info.
177 $data['gateways'] = self::get_active_payment_gateways();
178
179 // WcPay settings info.
180 $data['wcpay_settings'] = self::get_wcpay_settings();
181
182 // Shipping method info.
183 $data['shipping_methods'] = self::get_active_shipping_methods();
184
185 // Features.
186 $data['enabled_features'] = self::get_enabled_features();
187
188 // Get all WooCommerce options info.
189 $data['settings'] = self::get_all_woocommerce_options_values();
190
191 // Template overrides.
192 $data['template_overrides'] = self::get_all_template_overrides();
193
194 // Cart & checkout tech (blocks or shortcodes).
195 $data['cart_checkout'] = self::get_cart_checkout_info();
196
197 // Mini Cart block, which only exists since wp 5.9.
198 if ( version_compare( get_bloginfo( 'version' ), '5.9', '>=' ) ) {
199 $data['mini_cart_block'] = self::get_mini_cart_info();
200 }
201
202 /**
203 * Filter whether to disable admin tracking.
204 *
205 * @since 5.2.0
206 */
207 $data['wc_admin_disabled'] = apply_filters( 'woocommerce_admin_disabled', false ) ? 'yes' : 'no';
208
209 // Mobile info.
210 $data['wc_mobile_usage'] = self::get_woocommerce_mobile_usage();
211
212 /**
213 * Filter the data that's sent with the tracker.
214 *
215 * @since 2.3.0
216 */
217 return apply_filters( 'woocommerce_tracker_data', $data );
218 }
219
220 /**
221 * Get the current theme info, theme name and version.
222 *
223 * @return array
224 */
225 public static function get_theme_info() {
226 $theme_data = wp_get_theme();
227 $theme_child_theme = wc_bool_to_string( is_child_theme() );
228 $theme_wc_support = wc_bool_to_string( current_theme_supports( 'woocommerce' ) );
229 $theme_is_block_theme = wc_bool_to_string( wc_current_theme_is_fse_theme() );
230
231 return array(
232 'name' => $theme_data->Name, // @phpcs:ignore
233 'version' => $theme_data->Version, // @phpcs:ignore
234 'child_theme' => $theme_child_theme,
235 'wc_support' => $theme_wc_support,
236 'block_theme' => $theme_is_block_theme,
237 );
238 }
239
240 /**
241 * Get WordPress related data.
242 *
243 * @return array
244 */
245 private static function get_wordpress_info() {
246 $wp_data = array();
247
248 $memory = wc_let_to_num( WP_MEMORY_LIMIT );
249
250 if ( function_exists( 'memory_get_usage' ) ) {
251 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- False positive.
252 $system_memory = wc_let_to_num( @ini_get( 'memory_limit' ) );
253 $memory = max( $memory, $system_memory );
254 }
255
256 // WordPress 5.5+ environment type specification.
257 // 'production' is the default in WP, thus using it as a default here, too.
258 $environment_type = 'production';
259 if ( function_exists( 'wp_get_environment_type' ) ) {
260 $environment_type = wp_get_environment_type();
261 }
262
263 $wp_data['memory_limit'] = size_format( $memory );
264 $wp_data['debug_mode'] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No';
265 $wp_data['locale'] = get_locale();
266 $wp_data['version'] = get_bloginfo( 'version' );
267 $wp_data['multisite'] = is_multisite() ? 'Yes' : 'No';
268 $wp_data['env_type'] = $environment_type;
269 $wp_data['dropins'] = array_keys( get_dropins() );
270
271 return $wp_data;
272 }
273
274 /**
275 * Get server related info.
276 *
277 * @return array
278 */
279 private static function get_server_info() {
280 $server_data = array();
281
282 if ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
283 $server_data['software'] = $_SERVER['SERVER_SOFTWARE']; // @phpcs:ignore
284 }
285
286 if ( function_exists( 'phpversion' ) ) {
287 $server_data['php_version'] = phpversion();
288 }
289
290 if ( function_exists( 'ini_get' ) ) {
291 $server_data['php_post_max_size'] = size_format( wc_let_to_num( ini_get( 'post_max_size' ) ) );
292 $server_data['php_time_limt'] = ini_get( 'max_execution_time' );
293 $server_data['php_max_input_vars'] = ini_get( 'max_input_vars' );
294 $server_data['php_suhosin'] = extension_loaded( 'suhosin' ) ? 'Yes' : 'No';
295 }
296
297 $database_version = wc_get_server_database_version();
298 $server_data['mysql_version'] = $database_version['number'];
299
300 $server_data['php_max_upload_size'] = size_format( wp_max_upload_size() );
301 $server_data['php_default_timezone'] = date_default_timezone_get();
302 $server_data['php_soap'] = class_exists( 'SoapClient' ) ? 'Yes' : 'No';
303 $server_data['php_fsockopen'] = function_exists( 'fsockopen' ) ? 'Yes' : 'No';
304 $server_data['php_curl'] = function_exists( 'curl_init' ) ? 'Yes' : 'No';
305
306 return $server_data;
307 }
308
309 /**
310 * Get all plugins grouped into activated or not.
311 *
312 * @return array
313 */
314 private static function get_all_plugins() {
315 // Ensure get_plugins function is loaded.
316 if ( ! function_exists( 'get_plugins' ) ) {
317 include ABSPATH . '/wp-admin/includes/plugin.php';
318 }
319
320 $plugins = wc_get_container()->get( LegacyProxy::class )->call_function( 'get_plugins' );
321 $active_plugins_keys = get_option( 'active_plugins', array() );
322 $active_plugins = array();
323
324 foreach ( $plugins as $k => $v ) {
325 // Take care of formatting the data how we want it.
326 $formatted = array();
327 $formatted['name'] = wp_strip_all_tags( $v['Name'] );
328 if ( isset( $v['Version'] ) ) {
329 $formatted['version'] = wp_strip_all_tags( $v['Version'] );
330 }
331 if ( isset( $v['Author'] ) ) {
332 $formatted['author'] = wp_strip_all_tags( $v['Author'] );
333 }
334 if ( isset( $v['Network'] ) ) {
335 $formatted['network'] = wp_strip_all_tags( $v['Network'] );
336 }
337 if ( isset( $v['PluginURI'] ) ) {
338 $formatted['plugin_uri'] = wp_strip_all_tags( $v['PluginURI'] );
339 }
340 $formatted['feature_compatibility'] = array();
341 if ( wc_get_container()->get( PluginUtil::class )->is_woocommerce_aware_plugin( $k ) ) {
342 $formatted['feature_compatibility'] = array_filter( FeaturesUtil::get_compatible_features_for_plugin( $k ) );
343 }
344 if ( in_array( $k, $active_plugins_keys, true ) ) {
345 // Remove active plugins from list so we can show active and inactive separately.
346 unset( $plugins[ $k ] );
347 $active_plugins[ $k ] = $formatted;
348 } else {
349 $plugins[ $k ] = $formatted;
350 }
351 }
352
353 return array(
354 'active_plugins' => $active_plugins,
355 'inactive_plugins' => $plugins,
356 );
357 }
358
359 /**
360 * Get the settings of WooCommerce Payments plugin
361 *
362 * @return array
363 */
364 private static function get_wcpay_settings() {
365 return get_option( 'woocommerce_woocommerce_payments_settings' );
366 }
367
368 /**
369 * Check to see if the helper is connected to WooCommerce.com
370 *
371 * @return string
372 */
373 private static function get_helper_connected() {
374 if ( class_exists( 'WC_Helper_Options' ) && is_callable( 'WC_Helper_Options::get' ) ) {
375 $authenticated = WC_Helper_Options::get( 'auth' );
376 } else {
377 $authenticated = '';
378 }
379 return ( ! empty( $authenticated ) ) ? 'yes' : 'no';
380 }
381
382
383 /**
384 * Get user totals based on user role.
385 *
386 * @return array
387 */
388 private static function get_user_counts() {
389 $user_count = array();
390 $user_count_data = count_users();
391 $user_count['total'] = $user_count_data['total_users'];
392
393 // Get user count based on user role.
394 foreach ( $user_count_data['avail_roles'] as $role => $count ) {
395 $user_count[ $role ] = $count;
396 }
397
398 return $user_count;
399 }
400
401 /**
402 * Get product totals based on product type.
403 *
404 * @return array
405 */
406 public static function get_product_counts() {
407 $product_count = array();
408 $product_count_data = wp_count_posts( 'product' );
409 $product_count['total'] = $product_count_data->publish;
410
411 $product_statuses = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
412 foreach ( $product_statuses as $product_status ) {
413 $product_count[ $product_status->name ] = $product_status->count;
414 }
415
416 return $product_count;
417 }
418
419 /**
420 * Get order counts.
421 *
422 * @return array
423 */
424 private static function get_order_counts() {
425 $order_count = array();
426 foreach ( wc_get_order_statuses() as $status_slug => $status_name ) {
427 $order_count[ $status_slug ] = wc_orders_count( $status_slug );
428 }
429 return $order_count;
430 }
431
432 /**
433 * Combine all order data.
434 *
435 * @return array
436 */
437 private static function get_orders() {
438 $order_dates = self::get_order_dates();
439 $order_counts = self::get_order_counts();
440 $order_totals = self::get_order_totals();
441 $order_gateways = self::get_orders_by_gateway();
442 $order_origin = self::get_orders_origins();
443
444 return array_merge( $order_dates, $order_counts, $order_totals, $order_gateways, $order_origin );
445 }
446
447 /**
448 * Get order totals.
449 *
450 * @since 5.4.0
451 * @return array
452 */
453 private static function get_order_totals() {
454 global $wpdb;
455
456 $orders_table = OrdersTableDataStore::get_orders_table_name();
457
458 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
459 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
460 $gross_total = $wpdb->get_var(
461 "
462 SELECT SUM(total_amount) AS 'gross_total'
463 FROM $orders_table
464 WHERE status in ('wc-completed', 'wc-refunded');
465 "
466 );
467 // phpcs:enable
468 } else {
469 $gross_total = $wpdb->get_var(
470 "
471 SELECT
472 SUM( order_meta.meta_value ) AS 'gross_total'
473 FROM {$wpdb->prefix}posts AS orders
474 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
475 WHERE order_meta.meta_key = '_order_total'
476 AND orders.post_status in ( 'wc-completed', 'wc-refunded' )
477 GROUP BY order_meta.meta_key
478 "
479 );
480 }
481
482 if ( is_null( $gross_total ) ) {
483 $gross_total = 0;
484 }
485
486 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
487 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
488 $processing_gross_total = $wpdb->get_var(
489 "
490 SELECT SUM(total_amount) AS 'gross_total'
491 FROM $orders_table
492 WHERE status = 'wc-processing';
493 "
494 );
495 // phpcs:enable
496 } else {
497 $processing_gross_total = $wpdb->get_var(
498 "
499 SELECT
500 SUM( order_meta.meta_value ) AS 'gross_total'
501 FROM {$wpdb->prefix}posts AS orders
502 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
503 WHERE order_meta.meta_key = '_order_total'
504 AND orders.post_status = 'wc-processing'
505 GROUP BY order_meta.meta_key
506 "
507 );
508 }
509
510 if ( is_null( $processing_gross_total ) ) {
511 $processing_gross_total = 0;
512 }
513
514 return array(
515 'gross' => $gross_total,
516 'processing_gross' => $processing_gross_total,
517 );
518 }
519
520 /**
521 * Get last order date.
522 *
523 * @return string
524 */
525 private static function get_order_dates() {
526 global $wpdb;
527
528 $orders_table = OrdersTableDataStore::get_orders_table_name();
529 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
530 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
531 $min_max = $wpdb->get_row(
532 "
533 SELECT
534 MIN( date_created_gmt ) as 'first', MAX( date_created_gmt ) as 'last'
535 FROM $orders_table
536 WHERE status = 'wc-completed';
537 ",
538 ARRAY_A
539 );
540 // phpcs:enable
541 } else {
542 $min_max = $wpdb->get_row(
543 "
544 SELECT
545 MIN( post_date_gmt ) as 'first', MAX( post_date_gmt ) as 'last'
546 FROM {$wpdb->prefix}posts
547 WHERE post_type = 'shop_order'
548 AND post_status = 'wc-completed'
549 ",
550 ARRAY_A
551 );
552 }
553
554 if ( is_null( $min_max ) ) {
555 $min_max = array(
556 'first' => '-',
557 'last' => '-',
558 );
559 }
560
561 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
562 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
563 $processing_min_max = $wpdb->get_row(
564 "
565 SELECT
566 MIN( date_created_gmt ) as 'processing_first', MAX( date_created_gmt ) as 'processing_last'
567 FROM $orders_table
568 WHERE status = 'wc-processing';
569 ",
570 ARRAY_A
571 );
572 // phpcs:enable
573 } else {
574 $processing_min_max = $wpdb->get_row(
575 "
576 SELECT
577 MIN( post_date_gmt ) as 'processing_first', MAX( post_date_gmt ) as 'processing_last'
578 FROM {$wpdb->prefix}posts
579 WHERE post_type = 'shop_order'
580 AND post_status = 'wc-processing'
581 ",
582 ARRAY_A
583 );
584 }
585
586 if ( is_null( $processing_min_max ) ) {
587 $processing_min_max = array(
588 'processing_first' => '-',
589 'processing_last' => '-',
590 );
591 }
592
593 return array_merge( $min_max, $processing_min_max );
594 }
595
596 /**
597 * Extract the group key for an associative array of objects which have unique ids in the key.
598 * A 'group_key' property is introduced in the object.
599 * For example, two objects with keys like 'WooDataPay ** #123' and 'WooDataPay ** #78' would
600 * both have a group_key of 'WooDataPay **' after this function call.
601 *
602 * @param array $objects The array of objects that need to be grouped.
603 * @param string $default_key The property that will be the default group_key.
604 * @return array Contains the objects with a group_key property.
605 */
606 private static function extract_group_key( $objects, $default_key ) {
607 $keys = array_keys( $objects );
608
609 // Sort keys by length and then by characters within the same length keys.
610 usort(
611 $keys,
612 function( $a, $b ) {
613 if ( strlen( $a ) === strlen( $b ) ) {
614 return strcmp( $a, $b );
615 }
616 return ( strlen( $a ) < strlen( $b ) ) ? -1 : 1;
617 }
618 );
619
620 // Look for common tokens in every pair of adjacent keys.
621 $prev = '';
622 foreach ( $keys as $key ) {
623 if ( $prev ) {
624 $comm_tokens = array();
625
626 // Tokenize the current and previous gateway names.
627 $curr_tokens = preg_split( '/[ :,\-_]+/', $key );
628 $prev_tokens = preg_split( '/[ :,\-_]+/', $prev );
629
630 $len_curr = is_array( $curr_tokens ) ? count( $curr_tokens ) : 0;
631 $len_prev = is_array( $prev_tokens ) ? count( $prev_tokens ) : 0;
632
633 $index_unique = -1;
634 // Gather the common tokens.
635 // Let us allow for the unique reference id to be anywhere in the name.
636 for ( $i = 0; $i < $len_curr && $i < $len_prev; $i++ ) {
637 if ( $curr_tokens[ $i ] === $prev_tokens[ $i ] ) {
638 $comm_tokens[] = $curr_tokens[ $i ];
639 } elseif ( preg_match( '/\d/', $curr_tokens[ $i ] ) && preg_match( '/\d/', $prev_tokens[ $i ] ) ) {
640 $index_unique = $i;
641 }
642 }
643
644 // If only one token is different, and those tokens contain digits, then that could be the unique id.
645 if ( $len_curr - count( $comm_tokens ) <= 1 && count( $comm_tokens ) > 0 && $index_unique > -1 ) {
646 $objects[ $key ]->group_key = implode( ' ', $comm_tokens );
647 $objects[ $prev ]->group_key = implode( ' ', $comm_tokens );
648 } else {
649 $objects[ $key ]->group_key = $objects[ $key ]->$default_key;
650 }
651 } else {
652 $objects[ $key ]->group_key = $objects[ $key ]->$default_key;
653 }
654 $prev = $key;
655 }
656 return $objects;
657 }
658
659 /**
660 * Get order details by gateway.
661 *
662 * @return array
663 */
664 private static function get_orders_by_gateway() {
665 global $wpdb;
666
667 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
668 $orders_table = OrdersTableDataStore::get_orders_table_name();
669 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
670 $orders_and_gateway_details = $wpdb->get_results(
671 "
672 SELECT payment_method AS gateway, currency AS currency, SUM( total_amount ) AS totals, count( id ) AS counts
673 FROM $orders_table
674 WHERE status IN ( 'wc-completed', 'wc-processing', 'wc-refunded' )
675 GROUP BY gateway, currency;
676 "
677 );
678 // phpcs:enable
679 } else {
680 $orders_and_gateway_details = $wpdb->get_results(
681 "
682 SELECT
683 gateway, currency, SUM(total) AS totals, COUNT(order_id) AS counts
684 FROM (
685 SELECT
686 orders.id AS order_id,
687 MAX(CASE WHEN meta_key = '_payment_method' THEN meta_value END) gateway,
688 MAX(CASE WHEN meta_key = '_order_total' THEN meta_value END) total,
689 MAX(CASE WHEN meta_key = '_order_currency' THEN meta_value END) currency
690 FROM
691 {$wpdb->prefix}posts orders
692 LEFT JOIN
693 {$wpdb->prefix}postmeta order_meta ON order_meta.post_id = orders.id
694 WHERE orders.post_type = 'shop_order'
695 AND orders.post_status in ( 'wc-completed', 'wc-processing', 'wc-refunded' )
696 AND meta_key in( '_payment_method','_order_total','_order_currency')
697 GROUP BY orders.id
698 ) order_gateways
699 GROUP BY gateway, currency
700 "
701 );
702 }
703
704 $orders_by_gateway_currency = array();
705
706 // The associative array that is created as the result of array_reduce is passed to extract_group_key()
707 // This function has the logic that will remove specific transaction identifiers that may sometimes be part of a
708 // payment method. For example, two payments methods like 'WooDataPay ** #123' and 'WooDataPay ** #78' would
709 // both have the same group_key 'WooDataPay **'.
710 $orders_by_gateway = self::extract_group_key(
711 // Convert into an associative array with a combination of currency and gateway as key.
712 array_reduce(
713 $orders_and_gateway_details,
714 function( $result, $item ) {
715 $item->gateway = preg_replace( '/\s+/', ' ', $item->gateway );
716
717 // Introduce currency as a prefix for the key.
718 $key = $item->currency . '==' . $item->gateway;
719
720 $result[ $key ] = $item;
721 return $result;
722 },
723 array()
724 ),
725 'gateway'
726 );
727
728 // Aggregate using group_key.
729 foreach ( $orders_by_gateway as $orders_details ) {
730 $gkey = $orders_details->group_key;
731
732 // Remove currency as prefix of key for backward compatibility.
733 if ( str_contains( $gkey, '==' ) ) {
734 $tokens = preg_split( '/==/', $gkey );
735 $key = $tokens[1];
736 } else {
737 $key = $gkey;
738 }
739
740 $key = str_replace( array( 'payment method', 'payment gateway', 'gateway' ), '', strtolower( $key ) );
741 $key = trim( preg_replace( '/[: ,#*\-_]+/', ' ', $key ) );
742
743 // Add currency as postfix of gateway for backward compatibility.
744 $key = 'gateway_' . $key . '_' . $orders_details->currency;
745 $count_key = $key . '_count';
746 $total_key = $key . '_total';
747
748 if ( array_key_exists( $count_key, $orders_by_gateway_currency ) || array_key_exists( $total_key, $orders_by_gateway_currency ) ) {
749 $orders_by_gateway_currency[ $count_key ] = $orders_by_gateway_currency[ $count_key ] + $orders_details->counts;
750 $orders_by_gateway_currency[ $total_key ] = $orders_by_gateway_currency[ $total_key ] + $orders_details->totals;
751 } else {
752 $orders_by_gateway_currency[ $count_key ] = $orders_details->counts;
753 $orders_by_gateway_currency[ $total_key ] = $orders_details->totals;
754 }
755 }
756
757 return $orders_by_gateway_currency;
758 }
759
760 /**
761 * Get orders origin details.
762 *
763 * @return array
764 */
765 private static function get_orders_origins() {
766 global $wpdb;
767
768 if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
769 $op_table_name = OrdersTableDataStore::get_operational_data_table_name();
770 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
771 $orders_origin = $wpdb->get_results(
772 "
773 SELECT created_via as origin, COUNT( order_id ) as count
774 FROM $op_table_name
775 GROUP BY created_via;
776 "
777 );
778 // phpcs:enable
779 } else {
780 $orders_origin = $wpdb->get_results(
781 "
782 SELECT
783 meta_value as origin, COUNT( DISTINCT ( orders.id ) ) as count
784 FROM
785 $wpdb->posts orders
786 LEFT JOIN
787 $wpdb->postmeta order_meta ON order_meta.post_id = orders.id
788 WHERE
789 meta_key = '_created_via'
790 GROUP BY
791 meta_value;
792 "
793 );
794 }
795
796 // The associative array that is created as the result of array_reduce is passed to extract_group_key()
797 // This function has the logic that will remove specific identifiers that may sometimes be part of an origin.
798 // For example, two origins like 'Import #123' and 'Import ** #78' would both have a group_key 'Import **'.
799 $orders_and_origins = self::extract_group_key(
800 // Convert into an associative array with the origin as key.
801 array_reduce(
802 $orders_origin,
803 function( $result, $item ) {
804 $key = $item->origin;
805
806 $result[ $key ] = $item;
807 return $result;
808 },
809 array()
810 ),
811 'origin'
812 );
813
814 $orders_by_origin = array();
815
816 // Aggregate using group_key.
817 foreach ( $orders_and_origins as $origin ) {
818 $key = strtolower( $origin->group_key );
819
820 if ( array_key_exists( $key, $orders_by_origin ) ) {
821 $orders_by_origin[ $key ] = $orders_by_origin[ $key ] + (int) $origin->count;
822 } else {
823 $orders_by_origin[ $key ] = (int) $origin->count;
824 }
825 }
826
827 return array( 'created_via' => $orders_by_origin );
828 }
829
830 /**
831 * Get review counts for different statuses.
832 *
833 * @return array
834 */
835 private static function get_review_counts() {
836 global $wpdb;
837 $review_count = array( 'total' => 0 );
838 $status_map = array(
839 '0' => 'pending',
840 '1' => 'approved',
841 'trash' => 'trash',
842 'spam' => 'spam',
843 );
844 $counts = $wpdb->get_results(
845 "
846 SELECT comment_approved, COUNT(*) AS num_reviews
847 FROM {$wpdb->comments}
848 WHERE comment_type = 'review'
849 GROUP BY comment_approved
850 ",
851 ARRAY_A
852 );
853
854 if ( ! $counts ) {
855 return $review_count;
856 }
857
858 foreach ( $counts as $count ) {
859 $status = $count['comment_approved'];
860 if ( array_key_exists( $status, $status_map ) ) {
861 $review_count[ $status_map[ $status ] ] = $count['num_reviews'];
862 }
863 $review_count['total'] += $count['num_reviews'];
864 }
865
866 return $review_count;
867 }
868
869 /**
870 * Get the number of product categories.
871 *
872 * @return int
873 */
874 private static function get_category_counts() {
875 return wp_count_terms( 'product_cat' );
876 }
877
878 /**
879 * Get a list of all active payment gateways.
880 *
881 * @return array
882 */
883 private static function get_active_payment_gateways() {
884 $active_gateways = array();
885 $gateways = WC()->payment_gateways->payment_gateways();
886 foreach ( $gateways as $id => $gateway ) {
887 if ( isset( $gateway->enabled ) && 'yes' === $gateway->enabled ) {
888 $active_gateways[ $id ] = array(
889 'title' => $gateway->title,
890 'supports' => $gateway->supports,
891 );
892 }
893 }
894
895 return $active_gateways;
896 }
897
898
899 /**
900 * Get a list of all active shipping methods.
901 *
902 * @return array
903 */
904 private static function get_active_shipping_methods() {
905 $active_methods = array();
906 $shipping_methods = WC()->shipping()->get_shipping_methods();
907 foreach ( $shipping_methods as $id => $shipping_method ) {
908 if ( isset( $shipping_method->enabled ) && 'yes' === $shipping_method->enabled ) {
909 $active_methods[ $id ] = array(
910 'title' => $shipping_method->title,
911 'tax_status' => $shipping_method->tax_status,
912 );
913 }
914 }
915
916 return $active_methods;
917 }
918
919 /**
920 * Get an array of slugs for WC features that are enabled on the site.
921 *
922 * @return string[]
923 */
924 private static function get_enabled_features() {
925 $all_features = FeaturesUtil::get_features( true, true );
926 $enabled_features = array_filter(
927 $all_features,
928 function( $feature ) {
929 return $feature['is_enabled'];
930 }
931 );
932
933 return array_keys( $enabled_features );
934 }
935
936 /**
937 * Get all options starting with woocommerce_ prefix.
938 *
939 * @return array
940 */
941 private static function get_all_woocommerce_options_values() {
942 return array(
943 'version' => WC()->version,
944 'currency' => get_woocommerce_currency(),
945 'base_location' => WC()->countries->get_base_country(),
946 'base_state' => WC()->countries->get_base_state(),
947 'base_postcode' => WC()->countries->get_base_postcode(),
948 'selling_locations' => WC()->countries->get_allowed_countries(),
949 'api_enabled' => get_option( 'woocommerce_api_enabled', 'no' ),
950 'weight_unit' => get_option( 'woocommerce_weight_unit' ),
951 'dimension_unit' => get_option( 'woocommerce_dimension_unit' ),
952 'download_method' => get_option( 'woocommerce_file_download_method' ),
953 'download_require_login' => get_option( 'woocommerce_downloads_require_login' ),
954 'calc_taxes' => get_option( 'woocommerce_calc_taxes' ),
955 'coupons_enabled' => get_option( 'woocommerce_enable_coupons' ),
956 'guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
957 'checkout_login_reminder' => get_option( 'woocommerce_enable_checkout_login_reminder' ),
958 'secure_checkout' => get_option( 'woocommerce_force_ssl_checkout' ),
959 'enable_signup_and_login_from_checkout' => get_option( 'woocommerce_enable_signup_and_login_from_checkout' ),
960 'enable_myaccount_registration' => get_option( 'woocommerce_enable_myaccount_registration' ),
961 'registration_generate_username' => get_option( 'woocommerce_registration_generate_username' ),
962 'registration_generate_password' => get_option( 'woocommerce_registration_generate_password' ),
963 'hpos_sync_enabled' => get_option( 'woocommerce_custom_orders_table_data_sync_enabled' ),
964 'hpos_cot_authoritative' => get_option( 'woocommerce_custom_orders_table_enabled' ),
965 'hpos_transactions_enabled' => get_option( 'woocommerce_use_db_transactions_for_custom_orders_table_data_sync' ),
966 'hpos_transactions_level' => get_option( 'woocommerce_db_transactions_isolation_level_for_custom_orders_table_data_sync' ),
967 'show_marketplace_suggestions' => get_option( 'woocommerce_show_marketplace_suggestions' ),
968 );
969 }
970
971 /**
972 * Look for any template override and return filenames.
973 *
974 * @return array
975 */
976 private static function get_all_template_overrides() {
977 $override_data = array();
978 /**
979 * Filter the paths to scan for template overrides.
980 *
981 * @since 2.3.0
982 */
983 $template_paths = apply_filters( 'woocommerce_template_overrides_scan_paths', array( 'WooCommerce' => WC()->plugin_path() . '/templates/' ) );
984 $scanned_files = array();
985
986 require_once WC()->plugin_path() . '/includes/admin/class-wc-admin-status.php';
987
988 foreach ( $template_paths as $plugin_name => $template_path ) {
989 $scanned_files[ $plugin_name ] = WC_Admin_Status::scan_template_files( $template_path );
990 }
991
992 foreach ( $scanned_files as $plugin_name => $files ) {
993 foreach ( $files as $file ) {
994 if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
995 $theme_file = get_stylesheet_directory() . '/' . $file;
996 } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) {
997 $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file;
998 } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
999 $theme_file = get_template_directory() . '/' . $file;
1000 } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) {
1001 $theme_file = get_template_directory() . '/' . WC()->template_path() . $file;
1002 } else {
1003 $theme_file = false;
1004 }
1005
1006 if ( false !== $theme_file ) {
1007 $override_data[] = basename( $theme_file );
1008 }
1009 }
1010 }
1011 return $override_data;
1012 }
1013
1014 /**
1015 * Search a specific post for text content.
1016 *
1017 * @param integer $post_id The id of the post to search.
1018 * @param string $text The text to search for.
1019 * @return string 'Yes' if post contains $text (otherwise 'No').
1020 */
1021 public static function post_contains_text( $post_id, $text ) {
1022 global $wpdb;
1023
1024 // Search for the text anywhere in the post.
1025 $wildcarded = "%{$text}%";
1026
1027 $result = $wpdb->get_var(
1028 $wpdb->prepare(
1029 "
1030 SELECT COUNT( * ) FROM {$wpdb->prefix}posts
1031 WHERE ID=%d
1032 AND {$wpdb->prefix}posts.post_content LIKE %s
1033 ",
1034 array( $post_id, $wildcarded )
1035 )
1036 );
1037
1038 return ( '0' !== $result ) ? 'Yes' : 'No';
1039 }
1040
1041
1042 /**
1043 * Get tracker data for a specific block type on a woocommerce page.
1044 *
1045 * @param string $block_name The name (id) of a block, e.g. `woocommerce/cart`.
1046 * @param string $woo_page_name The woo page to search, e.g. `cart`.
1047 * @return array Associative array of tracker data with keys:
1048 * - page_contains_block
1049 * - block_attributes
1050 */
1051 public static function get_block_tracker_data( $block_name, $woo_page_name ) {
1052 $blocks = WC_Blocks_Utils::get_blocks_from_page( $block_name, $woo_page_name );
1053
1054 $block_present = false;
1055 $attributes = array();
1056 if ( $blocks && count( $blocks ) ) {
1057 // Return any customised attributes from the first block.
1058 $block_present = true;
1059 $attributes = $blocks[0]['attrs'];
1060 }
1061
1062 return array(
1063 'page_contains_block' => $block_present ? 'Yes' : 'No',
1064 'block_attributes' => $attributes,
1065 );
1066 }
1067
1068 /**
1069 * Get tracker data for a pickup location method.
1070 *
1071 * @return array Associative array of tracker data with keys:
1072 * - pickup_location_enabled
1073 * - pickup_locations_count
1074 */
1075 public static function get_pickup_location_data() {
1076 $pickup_location_enabled = false;
1077 $pickup_location_pickup_locations = get_option( 'pickup_location_pickup_locations', array() );
1078 $pickup_locations_count = is_countable( $pickup_location_pickup_locations ) ? count( $pickup_location_pickup_locations ) : 0;
1079
1080 // Get the available shipping methods.
1081 $shipping_methods = WC()->shipping()->get_shipping_methods();
1082
1083 // Check if the desired shipping method is enabled.
1084 if ( isset( $shipping_methods['pickup_location'] ) && $shipping_methods['pickup_location']->is_enabled() ) {
1085 $pickup_location_enabled = true;
1086 }
1087
1088 return array(
1089 'pickup_location_enabled' => $pickup_location_enabled,
1090 'pickup_locations_count' => $pickup_locations_count,
1091 );
1092 }
1093
1094 /**
1095 * Get tracker data for additional fields on the checkout page.
1096 *
1097 * @return array Array of fields count and names.
1098 */
1099 public static function get_checkout_additional_fields_data() {
1100 $additional_fields_controller = Package::container()->get( CheckoutFields::class );
1101
1102 return array(
1103 'fields_count' => count( $additional_fields_controller->get_additional_fields() ),
1104 'fields_names' => array_keys( $additional_fields_controller->get_additional_fields() ),
1105 );
1106 }
1107 /**
1108 * Get info about the cart & checkout pages.
1109 *
1110 * @return array
1111 */
1112 public static function get_cart_checkout_info() {
1113 $cart_page_id = wc_get_page_id( 'cart' );
1114 $checkout_page_id = wc_get_page_id( 'checkout' );
1115
1116 $cart_block_data = self::get_block_tracker_data( 'woocommerce/cart', 'cart' );
1117 $checkout_block_data = self::get_block_tracker_data( 'woocommerce/checkout', 'checkout' );
1118
1119 $pickup_location_data = self::get_pickup_location_data();
1120
1121 $additional_fields_data = self::get_checkout_additional_fields_data();
1122
1123 return array(
1124 'cart_page_contains_cart_shortcode' => self::post_contains_text(
1125 $cart_page_id,
1126 '[woocommerce_cart]'
1127 ),
1128 'checkout_page_contains_checkout_shortcode' => self::post_contains_text(
1129 $checkout_page_id,
1130 '[woocommerce_checkout]'
1131 ),
1132
1133 'cart_page_contains_cart_block' => $cart_block_data['page_contains_block'],
1134 'cart_block_attributes' => $cart_block_data['block_attributes'],
1135 'checkout_page_contains_checkout_block' => $checkout_block_data['page_contains_block'],
1136 'checkout_block_attributes' => $checkout_block_data['block_attributes'],
1137 'pickup_location' => $pickup_location_data,
1138 'additional_fields' => $additional_fields_data,
1139 );
1140 }
1141
1142 /**
1143 * Get info about the Mini Cart Block.
1144 *
1145 * @return array
1146 */
1147 private static function get_mini_cart_info() {
1148 $mini_cart_block_name = 'woocommerce/mini-cart';
1149 $mini_cart_block_data = wc_current_theme_is_fse_theme() ? BlocksUtil::get_block_from_template_part( $mini_cart_block_name, 'header' ) : BlocksUtil::get_blocks_from_widget_area( $mini_cart_block_name );
1150 return array(
1151 'mini_cart_used' => empty( $mini_cart_block_data[0] ) ? 'No' : 'Yes',
1152 'mini_cart_block_attributes' => empty( $mini_cart_block_data[0] ) ? array() : $mini_cart_block_data[0]['attrs'],
1153 );
1154 }
1155
1156 /**
1157 * Get info about WooCommerce Mobile App usage
1158 *
1159 * @return array
1160 */
1161 public static function get_woocommerce_mobile_usage() {
1162 return get_option( 'woocommerce_mobile_app_usage' );
1163 }
1164 }
1165
1166 WC_Tracker::init();
1167