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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 5 years ago admin 5 years ago cli 5 years ago customizer 5 years ago data-stores 5 years ago emails 5 years ago export 5 years ago gateways 5 years ago import 5 years ago integrations 5 years ago interfaces 5 years ago legacy 5 years ago libraries 6 years ago log-handlers 5 years ago payment-tokens 5 years ago queue 5 years ago rest-api 5 years ago shipping 5 years ago shortcodes 5 years ago theme-support 5 years ago tracks 5 years ago traits 5 years ago walkers 5 years ago wccom-site 5 years ago widgets 5 years ago class-wc-ajax.php 5 years ago class-wc-api.php 5 years ago class-wc-auth.php 5 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 5 years ago class-wc-cart-fees.php 5 years ago class-wc-cart-session.php 5 years ago class-wc-cart-totals.php 5 years ago class-wc-cart.php 5 years ago class-wc-checkout.php 5 years ago class-wc-cli.php 8 years ago class-wc-comments.php 5 years ago class-wc-countries.php 5 years ago class-wc-coupon.php 5 years ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 5 years ago class-wc-customer.php 5 years ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 6 years ago class-wc-datetime.php 5 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 7 years ago class-wc-discounts.php 5 years ago class-wc-download-handler.php 5 years ago class-wc-emails.php 5 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 5 years ago class-wc-frontend-scripts.php 5 years ago class-wc-geo-ip.php 5 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 5 years ago class-wc-https.php 5 years ago class-wc-install.php 5 years ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 5 years ago class-wc-logger.php 5 years ago class-wc-meta-data.php 7 years ago class-wc-order-factory.php 5 years ago class-wc-order-item-coupon.php 5 years ago class-wc-order-item-fee.php 5 years ago class-wc-order-item-meta.php 5 years ago class-wc-order-item-product.php 5 years ago class-wc-order-item-shipping.php 5 years ago class-wc-order-item-tax.php 5 years ago class-wc-order-item.php 5 years ago class-wc-order-query.php 5 years ago class-wc-order-refund.php 5 years ago class-wc-order.php 5 years ago class-wc-payment-gateways.php 5 years ago class-wc-payment-tokens.php 5 years ago class-wc-post-data.php 5 years ago class-wc-post-types.php 5 years ago class-wc-privacy-background-process.php 5 years ago class-wc-privacy-erasers.php 6 years ago class-wc-privacy-exporters.php 6 years ago class-wc-privacy.php 6 years ago class-wc-product-attribute.php 5 years ago class-wc-product-download.php 5 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 5 years ago class-wc-product-variable.php 5 years ago class-wc-product-variation.php 5 years ago class-wc-query.php 5 years ago class-wc-rate-limiter.php 5 years ago class-wc-regenerate-images-request.php 5 years ago class-wc-regenerate-images.php 5 years ago class-wc-register-wp-admin-settings.php 5 years ago class-wc-rest-authentication.php 5 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 5 years ago class-wc-shipping-rate.php 5 years ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 5 years ago class-wc-shortcodes.php 5 years ago class-wc-structured-data.php 5 years ago class-wc-tax.php 5 years ago class-wc-template-loader.php 5 years ago class-wc-tracker.php 5 years ago class-wc-validation.php 5 years ago class-wc-webhook.php 5 years ago class-woocommerce.php 5 years ago wc-account-functions.php 5 years ago wc-attribute-functions.php 5 years ago wc-cart-functions.php 5 years ago wc-conditional-functions.php 5 years ago wc-core-functions.php 5 years ago wc-coupon-functions.php 5 years ago wc-deprecated-functions.php 5 years ago wc-formatting-functions.php 5 years ago wc-notice-functions.php 5 years ago wc-order-functions.php 5 years ago wc-order-item-functions.php 5 years ago wc-page-functions.php 6 years ago wc-product-functions.php 5 years ago wc-rest-functions.php 5 years ago wc-stock-functions.php 5 years ago wc-template-functions.php 5 years ago wc-template-hooks.php 5 years ago wc-term-functions.php 5 years ago wc-update-functions.php 5 years ago wc-user-functions.php 5 years ago wc-webhook-functions.php 5 years ago wc-widget-functions.php 5 years ago
class-wc-tracker.php
756 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
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * WooCommerce Tracker Class
19 */
20 class WC_Tracker {
21
22 /**
23 * URL to the WooThemes Tracker API endpoint.
24 *
25 * @var string
26 */
27 private static $api_url = 'https://tracking.woocommerce.com/v1/';
28
29 /**
30 * Hook into cron event.
31 */
32 public static function init() {
33 add_action( 'woocommerce_tracker_send_event', array( __CLASS__, 'send_tracking_data' ) );
34 }
35
36 /**
37 * Decide whether to send tracking data or not.
38 *
39 * @param boolean $override Should override?.
40 */
41 public static function send_tracking_data( $override = false ) {
42 // Don't trigger this on AJAX Requests.
43 if ( Constants::is_true( 'DOING_AJAX' ) ) {
44 return;
45 }
46
47 if ( ! apply_filters( 'woocommerce_tracker_send_override', $override ) ) {
48 // Send a maximum of once per week by default.
49 $last_send = self::get_last_send_time();
50 if ( $last_send && $last_send > apply_filters( 'woocommerce_tracker_last_send_interval', strtotime( '-1 week' ) ) ) {
51 return;
52 }
53 } else {
54 // Make sure there is at least a 1 hour delay between override sends, we don't want duplicate calls due to double clicking links.
55 $last_send = self::get_last_send_time();
56 if ( $last_send && $last_send > strtotime( '-1 hours' ) ) {
57 return;
58 }
59 }
60
61 // Update time first before sending to ensure it is set.
62 update_option( 'woocommerce_tracker_last_send', time() );
63
64 $params = self::get_tracking_data();
65 wp_safe_remote_post(
66 self::$api_url,
67 array(
68 'method' => 'POST',
69 'timeout' => 45,
70 'redirection' => 5,
71 'httpversion' => '1.0',
72 'blocking' => false,
73 'headers' => array( 'user-agent' => 'WooCommerceTracker/' . md5( esc_url_raw( home_url( '/' ) ) ) . ';' ),
74 'body' => wp_json_encode( $params ),
75 'cookies' => array(),
76 )
77 );
78 }
79
80 /**
81 * Get the last time tracking data was sent.
82 *
83 * @return int|bool
84 */
85 private static function get_last_send_time() {
86 return apply_filters( 'woocommerce_tracker_last_send_time', get_option( 'woocommerce_tracker_last_send', false ) );
87 }
88
89 /**
90 * Test whether this site is a staging site according to the Jetpack criteria.
91 *
92 * With Jetpack 8.1+, Jetpack::is_staging_site has been deprecated.
93 * \Automattic\Jetpack\Status::is_staging_site is the replacement.
94 * However, there are version of JP where \Automattic\Jetpack\Status exists, but does *not* contain is_staging_site method,
95 * so with those, code still needs to use the previous check as a fallback.
96 *
97 * @return bool
98 */
99 private static function is_jetpack_staging_site() {
100 if ( class_exists( '\Automattic\Jetpack\Status' ) ) {
101 // Preferred way of checking with Jetpack 8.1+.
102 $jp_status = new \Automattic\Jetpack\Status();
103 if ( is_callable( array( $jp_status, 'is_staging_site' ) ) ) {
104 return $jp_status->is_staging_site();
105 }
106 }
107
108 return ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_staging_site' ) && Jetpack::is_staging_site() );
109 }
110
111 /**
112 * Get all the tracking data.
113 *
114 * @return array
115 */
116 private static function get_tracking_data() {
117 $data = array();
118
119 // General site info.
120 $data['url'] = home_url();
121 $data['email'] = apply_filters( 'woocommerce_tracker_admin_email', get_option( 'admin_email' ) );
122 $data['theme'] = self::get_theme_info();
123
124 // WordPress Info.
125 $data['wp'] = self::get_wordpress_info();
126
127 // Server Info.
128 $data['server'] = self::get_server_info();
129
130 // Plugin info.
131 $all_plugins = self::get_all_plugins();
132 $data['active_plugins'] = $all_plugins['active_plugins'];
133 $data['inactive_plugins'] = $all_plugins['inactive_plugins'];
134
135 // Jetpack & WooCommerce Connect.
136
137 $data['jetpack_version'] = Constants::is_defined( 'JETPACK__VERSION' ) ? Constants::get_constant( 'JETPACK__VERSION' ) : 'none';
138 $data['jetpack_connected'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_active' ) && Jetpack::is_active() ) ? 'yes' : 'no';
139 $data['jetpack_is_staging'] = self::is_jetpack_staging_site() ? 'yes' : 'no';
140 $data['connect_installed'] = class_exists( 'WC_Connect_Loader' ) ? 'yes' : 'no';
141 $data['connect_active'] = ( class_exists( 'WC_Connect_Loader' ) && wp_next_scheduled( 'wc_connect_fetch_service_schemas' ) ) ? 'yes' : 'no';
142 $data['helper_connected'] = self::get_helper_connected();
143
144 // Store count info.
145 $data['users'] = self::get_user_counts();
146 $data['products'] = self::get_product_counts();
147 $data['orders'] = self::get_orders();
148 $data['reviews'] = self::get_review_counts();
149 $data['categories'] = self::get_category_counts();
150
151 // Payment gateway info.
152 $data['gateways'] = self::get_active_payment_gateways();
153
154 // Shipping method info.
155 $data['shipping_methods'] = self::get_active_shipping_methods();
156
157 // Get all WooCommerce options info.
158 $data['settings'] = self::get_all_woocommerce_options_values();
159
160 // Template overrides.
161 $data['template_overrides'] = self::get_all_template_overrides();
162
163 // Template overrides.
164 $data['admin_user_agents'] = self::get_admin_user_agents();
165
166 // Cart & checkout tech (blocks or shortcodes).
167 $data['cart_checkout'] = self::get_cart_checkout_info();
168
169 return apply_filters( 'woocommerce_tracker_data', $data );
170 }
171
172 /**
173 * Get the current theme info, theme name and version.
174 *
175 * @return array
176 */
177 public static function get_theme_info() {
178 $theme_data = wp_get_theme();
179 $theme_child_theme = wc_bool_to_string( is_child_theme() );
180 $theme_wc_support = wc_bool_to_string( current_theme_supports( 'woocommerce' ) );
181
182 return array(
183 'name' => $theme_data->Name, // @phpcs:ignore
184 'version' => $theme_data->Version, // @phpcs:ignore
185 'child_theme' => $theme_child_theme,
186 'wc_support' => $theme_wc_support,
187 );
188 }
189
190 /**
191 * Get WordPress related data.
192 *
193 * @return array
194 */
195 private static function get_wordpress_info() {
196 $wp_data = array();
197
198 $memory = wc_let_to_num( WP_MEMORY_LIMIT );
199
200 if ( function_exists( 'memory_get_usage' ) ) {
201 $system_memory = wc_let_to_num( @ini_get( 'memory_limit' ) );
202 $memory = max( $memory, $system_memory );
203 }
204
205 $wp_data['memory_limit'] = size_format( $memory );
206 $wp_data['debug_mode'] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No';
207 $wp_data['locale'] = get_locale();
208 $wp_data['version'] = get_bloginfo( 'version' );
209 $wp_data['multisite'] = is_multisite() ? 'Yes' : 'No';
210
211 return $wp_data;
212 }
213
214 /**
215 * Get server related info.
216 *
217 * @return array
218 */
219 private static function get_server_info() {
220 $server_data = array();
221
222 if ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
223 $server_data['software'] = $_SERVER['SERVER_SOFTWARE']; // @phpcs:ignore
224 }
225
226 if ( function_exists( 'phpversion' ) ) {
227 $server_data['php_version'] = phpversion();
228 }
229
230 if ( function_exists( 'ini_get' ) ) {
231 $server_data['php_post_max_size'] = size_format( wc_let_to_num( ini_get( 'post_max_size' ) ) );
232 $server_data['php_time_limt'] = ini_get( 'max_execution_time' );
233 $server_data['php_max_input_vars'] = ini_get( 'max_input_vars' );
234 $server_data['php_suhosin'] = extension_loaded( 'suhosin' ) ? 'Yes' : 'No';
235 }
236
237 $database_version = wc_get_server_database_version();
238 $server_data['mysql_version'] = $database_version['number'];
239
240 $server_data['php_max_upload_size'] = size_format( wp_max_upload_size() );
241 $server_data['php_default_timezone'] = date_default_timezone_get();
242 $server_data['php_soap'] = class_exists( 'SoapClient' ) ? 'Yes' : 'No';
243 $server_data['php_fsockopen'] = function_exists( 'fsockopen' ) ? 'Yes' : 'No';
244 $server_data['php_curl'] = function_exists( 'curl_init' ) ? 'Yes' : 'No';
245
246 return $server_data;
247 }
248
249 /**
250 * Get all plugins grouped into activated or not.
251 *
252 * @return array
253 */
254 private static function get_all_plugins() {
255 // Ensure get_plugins function is loaded.
256 if ( ! function_exists( 'get_plugins' ) ) {
257 include ABSPATH . '/wp-admin/includes/plugin.php';
258 }
259
260 $plugins = get_plugins();
261 $active_plugins_keys = get_option( 'active_plugins', array() );
262 $active_plugins = array();
263
264 foreach ( $plugins as $k => $v ) {
265 // Take care of formatting the data how we want it.
266 $formatted = array();
267 $formatted['name'] = strip_tags( $v['Name'] );
268 if ( isset( $v['Version'] ) ) {
269 $formatted['version'] = strip_tags( $v['Version'] );
270 }
271 if ( isset( $v['Author'] ) ) {
272 $formatted['author'] = strip_tags( $v['Author'] );
273 }
274 if ( isset( $v['Network'] ) ) {
275 $formatted['network'] = strip_tags( $v['Network'] );
276 }
277 if ( isset( $v['PluginURI'] ) ) {
278 $formatted['plugin_uri'] = strip_tags( $v['PluginURI'] );
279 }
280 if ( in_array( $k, $active_plugins_keys ) ) {
281 // Remove active plugins from list so we can show active and inactive separately.
282 unset( $plugins[ $k ] );
283 $active_plugins[ $k ] = $formatted;
284 } else {
285 $plugins[ $k ] = $formatted;
286 }
287 }
288
289 return array(
290 'active_plugins' => $active_plugins,
291 'inactive_plugins' => $plugins,
292 );
293 }
294
295 /**
296 * Check to see if the helper is connected to woocommerce.com
297 *
298 * @return string
299 */
300 private static function get_helper_connected() {
301 if ( class_exists( 'WC_Helper_Options' ) && is_callable( 'WC_Helper_Options::get' ) ) {
302 $authenticated = WC_Helper_Options::get( 'auth' );
303 } else {
304 $authenticated = '';
305 }
306 return ( ! empty( $authenticated ) ) ? 'yes' : 'no';
307 }
308
309
310 /**
311 * Get user totals based on user role.
312 *
313 * @return array
314 */
315 private static function get_user_counts() {
316 $user_count = array();
317 $user_count_data = count_users();
318 $user_count['total'] = $user_count_data['total_users'];
319
320 // Get user count based on user role.
321 foreach ( $user_count_data['avail_roles'] as $role => $count ) {
322 $user_count[ $role ] = $count;
323 }
324
325 return $user_count;
326 }
327
328 /**
329 * Get product totals based on product type.
330 *
331 * @return array
332 */
333 public static function get_product_counts() {
334 $product_count = array();
335 $product_count_data = wp_count_posts( 'product' );
336 $product_count['total'] = $product_count_data->publish;
337
338 $product_statuses = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
339 foreach ( $product_statuses as $product_status ) {
340 $product_count[ $product_status->name ] = $product_status->count;
341 }
342
343 return $product_count;
344 }
345
346 /**
347 * Get order counts
348 *
349 * @return array
350 */
351 private static function get_order_counts() {
352 $order_count = array();
353 $order_count_data = wp_count_posts( 'shop_order' );
354 foreach ( wc_get_order_statuses() as $status_slug => $status_name ) {
355 $order_count[ $status_slug ] = $order_count_data->{ $status_slug };
356 }
357 return $order_count;
358 }
359
360 /**
361 * Combine all order data.
362 *
363 * @return array
364 */
365 private static function get_orders() {
366 $order_dates = self::get_order_dates();
367 $order_counts = self::get_order_counts();
368 $order_totals = self::get_order_totals();
369
370 return array_merge( $order_dates, $order_counts, $order_totals );
371 }
372
373 /**
374 * Get review counts for different statuses.
375 *
376 * @return array
377 */
378 private static function get_review_counts() {
379 global $wpdb;
380 $review_count = array( 'total' => 0 );
381 $status_map = array(
382 '0' => 'pending',
383 '1' => 'approved',
384 'trash' => 'trash',
385 'spam' => 'spam',
386 );
387 $counts = $wpdb->get_results(
388 "
389 SELECT comment_approved, COUNT(*) AS num_reviews
390 FROM {$wpdb->comments}
391 WHERE comment_type = 'review'
392 GROUP BY comment_approved
393 ",
394 ARRAY_A
395 );
396
397 if ( ! $counts ) {
398 return $review_count;
399 }
400
401 foreach ( $counts as $count ) {
402 $status = $count['comment_approved'];
403 if ( array_key_exists( $status, $status_map ) ) {
404 $review_count[ $status_map[ $status ] ] = $count['num_reviews'];
405 }
406 $review_count['total'] += $count['num_reviews'];
407 }
408
409 return $review_count;
410 }
411
412 /**
413 * Get the number of product categories.
414 *
415 * @return int
416 */
417 private static function get_category_counts() {
418 return wp_count_terms( 'product_cat' );
419 }
420
421 /**
422 * Get a list of all active payment gateways.
423 *
424 * @return array
425 */
426 private static function get_active_payment_gateways() {
427 $active_gateways = array();
428 $gateways = WC()->payment_gateways->payment_gateways();
429 foreach ( $gateways as $id => $gateway ) {
430 if ( isset( $gateway->enabled ) && 'yes' === $gateway->enabled ) {
431 $active_gateways[ $id ] = array(
432 'title' => $gateway->title,
433 'supports' => $gateway->supports,
434 );
435 }
436 }
437
438 return $active_gateways;
439 }
440
441 /**
442 * Get a list of all active shipping methods.
443 *
444 * @return array
445 */
446 private static function get_active_shipping_methods() {
447 $active_methods = array();
448 $shipping_methods = WC()->shipping()->get_shipping_methods();
449 foreach ( $shipping_methods as $id => $shipping_method ) {
450 if ( isset( $shipping_method->enabled ) && 'yes' === $shipping_method->enabled ) {
451 $active_methods[ $id ] = array(
452 'title' => $shipping_method->title,
453 'tax_status' => $shipping_method->tax_status,
454 );
455 }
456 }
457
458 return $active_methods;
459 }
460
461 /**
462 * Get all options starting with woocommerce_ prefix.
463 *
464 * @return array
465 */
466 private static function get_all_woocommerce_options_values() {
467 return array(
468 'version' => WC()->version,
469 'currency' => get_woocommerce_currency(),
470 'base_location' => WC()->countries->get_base_country(),
471 'selling_locations' => WC()->countries->get_allowed_countries(),
472 'api_enabled' => get_option( 'woocommerce_api_enabled' ),
473 'weight_unit' => get_option( 'woocommerce_weight_unit' ),
474 'dimension_unit' => get_option( 'woocommerce_dimension_unit' ),
475 'download_method' => get_option( 'woocommerce_file_download_method' ),
476 'download_require_login' => get_option( 'woocommerce_downloads_require_login' ),
477 'calc_taxes' => get_option( 'woocommerce_calc_taxes' ),
478 'coupons_enabled' => get_option( 'woocommerce_enable_coupons' ),
479 'guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
480 'secure_checkout' => get_option( 'woocommerce_force_ssl_checkout' ),
481 'enable_signup_and_login_from_checkout' => get_option( 'woocommerce_enable_signup_and_login_from_checkout' ),
482 'enable_myaccount_registration' => get_option( 'woocommerce_enable_myaccount_registration' ),
483 'registration_generate_username' => get_option( 'woocommerce_registration_generate_username' ),
484 'registration_generate_password' => get_option( 'woocommerce_registration_generate_password' ),
485 );
486 }
487
488 /**
489 * Look for any template override and return filenames.
490 *
491 * @return array
492 */
493 private static function get_all_template_overrides() {
494 $override_data = array();
495 $template_paths = apply_filters( 'woocommerce_template_overrides_scan_paths', array( 'WooCommerce' => WC()->plugin_path() . '/templates/' ) );
496 $scanned_files = array();
497
498 require_once WC()->plugin_path() . '/includes/admin/class-wc-admin-status.php';
499
500 foreach ( $template_paths as $plugin_name => $template_path ) {
501 $scanned_files[ $plugin_name ] = WC_Admin_Status::scan_template_files( $template_path );
502 }
503
504 foreach ( $scanned_files as $plugin_name => $files ) {
505 foreach ( $files as $file ) {
506 if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
507 $theme_file = get_stylesheet_directory() . '/' . $file;
508 } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) {
509 $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file;
510 } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
511 $theme_file = get_template_directory() . '/' . $file;
512 } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) {
513 $theme_file = get_template_directory() . '/' . WC()->template_path() . $file;
514 } else {
515 $theme_file = false;
516 }
517
518 if ( false !== $theme_file ) {
519 $override_data[] = basename( $theme_file );
520 }
521 }
522 }
523 return $override_data;
524 }
525
526 /**
527 * When an admin user logs in, there user agent is tracked in user meta and collected here.
528 *
529 * @return array
530 */
531 private static function get_admin_user_agents() {
532 return array_filter( (array) get_option( 'woocommerce_tracker_ua', array() ) );
533 }
534
535 /**
536 * Get order totals
537 *
538 * @return array
539 */
540 public static function get_order_totals() {
541 global $wpdb;
542
543 $gross_total = $wpdb->get_var(
544 "
545 SELECT
546 SUM( order_meta.meta_value ) AS 'gross_total'
547 FROM {$wpdb->prefix}posts AS orders
548 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
549 WHERE order_meta.meta_key = '_order_total'
550 AND orders.post_status in ( 'wc-completed', 'wc-refunded' )
551 GROUP BY order_meta.meta_key
552 "
553 );
554
555 if ( is_null( $gross_total ) ) {
556 $gross_total = 0;
557 }
558
559 $processing_gross_total = $wpdb->get_var(
560 "
561 SELECT
562 SUM( order_meta.meta_value ) AS 'gross_total'
563 FROM {$wpdb->prefix}posts AS orders
564 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
565 WHERE order_meta.meta_key = '_order_total'
566 AND orders.post_status = 'wc-processing'
567 GROUP BY order_meta.meta_key
568 "
569 );
570
571 if ( is_null( $processing_gross_total ) ) {
572 $processing_gross_total = 0;
573 }
574
575 return array(
576 'gross' => $gross_total,
577 'processing_gross' => $processing_gross_total,
578 );
579 }
580
581 /**
582 * Get last order date
583 *
584 * @return string
585 */
586 private static function get_order_dates() {
587 global $wpdb;
588
589 $min_max = $wpdb->get_row(
590 "
591 SELECT
592 MIN( post_date_gmt ) as 'first', MAX( post_date_gmt ) as 'last'
593 FROM {$wpdb->prefix}posts
594 WHERE post_type = 'shop_order'
595 AND post_status = 'wc-completed'
596 ",
597 ARRAY_A
598 );
599
600 if ( is_null( $min_max ) ) {
601 $min_max = array(
602 'first' => '-',
603 'last' => '-',
604 );
605 }
606
607 $processing_min_max = $wpdb->get_row(
608 "
609 SELECT
610 MIN( post_date_gmt ) as 'processing_first', MAX( post_date_gmt ) as 'processing_last'
611 FROM {$wpdb->prefix}posts
612 WHERE post_type = 'shop_order'
613 AND post_status = 'wc-processing'
614 ",
615 ARRAY_A
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 * Search a specific post for text content.
630 *
631 * @param integer $post_id The id of the post to search.
632 * @param string $text The text to search for.
633 * @return string 'Yes' if post contains $text (otherwise 'No').
634 */
635 public static function post_contains_text( $post_id, $text ) {
636 global $wpdb;
637
638 // Search for the text anywhere in the post.
639 $wildcarded = "%{$text}%";
640
641 $result = $wpdb->get_var(
642 $wpdb->prepare(
643 "
644 SELECT COUNT( * ) FROM {$wpdb->prefix}posts
645 WHERE ID=%d
646 AND {$wpdb->prefix}posts.post_content LIKE %s
647 ",
648 array( $post_id, $wildcarded )
649 )
650 );
651
652 return ( '0' !== $result ) ? 'Yes' : 'No';
653 }
654
655 /**
656 * Get blocks from a woocommerce page.
657 *
658 * @param string $woo_page_name A woocommerce page e.g. `checkout` or `cart`.
659 * @return array Array of blocks as returned by parse_blocks().
660 */
661 private static function get_all_blocks_from_page( $woo_page_name ) {
662 $page_id = wc_get_page_id( $woo_page_name );
663
664 $page = get_post( $page_id );
665 if ( ! $page ) {
666 return array();
667 }
668
669 $blocks = parse_blocks( $page->post_content );
670 if ( ! $blocks ) {
671 return array();
672 }
673
674 return $blocks;
675 }
676
677 /**
678 * Get all instances of the specified block on a specific woo page
679 * (e.g. `cart` or `checkout` page).
680 *
681 * @param string $block_name The name (id) of a block, e.g. `woocommerce/cart`.
682 * @param string $woo_page_name The woo page to search, e.g. `cart`.
683 * @return array Array of blocks as returned by parse_blocks().
684 */
685 private static function get_blocks_from_page( $block_name, $woo_page_name ) {
686 $page_blocks = self::get_all_blocks_from_page( $woo_page_name );
687
688 // Get any instances of the specified block.
689 return array_values(
690 array_filter(
691 $page_blocks,
692 function ( $block ) use ( $block_name ) {
693 return ( $block_name === $block['blockName'] );
694 }
695 )
696 );
697 }
698
699 /**
700 * Get tracker data for a specific block type on a woocommerce page.
701 *
702 * @param string $block_name The name (id) of a block, e.g. `woocommerce/cart`.
703 * @param string $woo_page_name The woo page to search, e.g. `cart`.
704 * @return array Associative array of tracker data with keys:
705 * - page_contains_block
706 * - block_attributes
707 */
708 public static function get_block_tracker_data( $block_name, $woo_page_name ) {
709 $blocks = self::get_blocks_from_page( $block_name, $woo_page_name );
710
711 $block_present = false;
712 $attributes = array();
713 if ( $blocks && count( $blocks ) ) {
714 // Return any customised attributes from the first block.
715 $block_present = true;
716 $attributes = $blocks[0]['attrs'];
717 }
718
719 return array(
720 'page_contains_block' => $block_present ? 'Yes' : 'No',
721 'block_attributes' => $attributes,
722 );
723 }
724
725 /**
726 * Get info about the cart & checkout pages.
727 *
728 * @return array
729 */
730 public static function get_cart_checkout_info() {
731 $cart_page_id = wc_get_page_id( 'cart' );
732 $checkout_page_id = wc_get_page_id( 'checkout' );
733
734 $cart_block_data = self::get_block_tracker_data( 'woocommerce/cart', 'cart' );
735 $checkout_block_data = self::get_block_tracker_data( 'woocommerce/checkout', 'checkout' );
736
737 return array(
738 'cart_page_contains_cart_shortcode' => self::post_contains_text(
739 $cart_page_id,
740 '[woocommerce_cart]'
741 ),
742 'checkout_page_contains_checkout_shortcode' => self::post_contains_text(
743 $checkout_page_id,
744 '[woocommerce_checkout]'
745 ),
746
747 'cart_page_contains_cart_block' => $cart_block_data['page_contains_block'],
748 'cart_block_attributes' => $cart_block_data['block_attributes'],
749 'checkout_page_contains_checkout_block' => $checkout_block_data['page_contains_block'],
750 'checkout_block_attributes' => $checkout_block_data['block_attributes'],
751 );
752 }
753 }
754
755 WC_Tracker::init();
756