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