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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 5 years ago admin 5 years ago cli 5 years ago customizer 5 years ago data-stores 4 years ago emails 5 years ago export 5 years ago gateways 4 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 4 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 5 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 4 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 5 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 4 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
764 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 // WordPress 5.5+ environment type specification.
206 // 'production' is the default in WP, thus using it as a default here, too.
207 $environment_type = 'production';
208 if ( function_exists( 'wp_get_environment_type' ) ) {
209 $environment_type = wp_get_environment_type();
210 }
211
212 $wp_data['memory_limit'] = size_format( $memory );
213 $wp_data['debug_mode'] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No';
214 $wp_data['locale'] = get_locale();
215 $wp_data['version'] = get_bloginfo( 'version' );
216 $wp_data['multisite'] = is_multisite() ? 'Yes' : 'No';
217 $wp_data['env_type'] = $environment_type;
218
219 return $wp_data;
220 }
221
222 /**
223 * Get server related info.
224 *
225 * @return array
226 */
227 private static function get_server_info() {
228 $server_data = array();
229
230 if ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
231 $server_data['software'] = $_SERVER['SERVER_SOFTWARE']; // @phpcs:ignore
232 }
233
234 if ( function_exists( 'phpversion' ) ) {
235 $server_data['php_version'] = phpversion();
236 }
237
238 if ( function_exists( 'ini_get' ) ) {
239 $server_data['php_post_max_size'] = size_format( wc_let_to_num( ini_get( 'post_max_size' ) ) );
240 $server_data['php_time_limt'] = ini_get( 'max_execution_time' );
241 $server_data['php_max_input_vars'] = ini_get( 'max_input_vars' );
242 $server_data['php_suhosin'] = extension_loaded( 'suhosin' ) ? 'Yes' : 'No';
243 }
244
245 $database_version = wc_get_server_database_version();
246 $server_data['mysql_version'] = $database_version['number'];
247
248 $server_data['php_max_upload_size'] = size_format( wp_max_upload_size() );
249 $server_data['php_default_timezone'] = date_default_timezone_get();
250 $server_data['php_soap'] = class_exists( 'SoapClient' ) ? 'Yes' : 'No';
251 $server_data['php_fsockopen'] = function_exists( 'fsockopen' ) ? 'Yes' : 'No';
252 $server_data['php_curl'] = function_exists( 'curl_init' ) ? 'Yes' : 'No';
253
254 return $server_data;
255 }
256
257 /**
258 * Get all plugins grouped into activated or not.
259 *
260 * @return array
261 */
262 private static function get_all_plugins() {
263 // Ensure get_plugins function is loaded.
264 if ( ! function_exists( 'get_plugins' ) ) {
265 include ABSPATH . '/wp-admin/includes/plugin.php';
266 }
267
268 $plugins = get_plugins();
269 $active_plugins_keys = get_option( 'active_plugins', array() );
270 $active_plugins = array();
271
272 foreach ( $plugins as $k => $v ) {
273 // Take care of formatting the data how we want it.
274 $formatted = array();
275 $formatted['name'] = strip_tags( $v['Name'] );
276 if ( isset( $v['Version'] ) ) {
277 $formatted['version'] = strip_tags( $v['Version'] );
278 }
279 if ( isset( $v['Author'] ) ) {
280 $formatted['author'] = strip_tags( $v['Author'] );
281 }
282 if ( isset( $v['Network'] ) ) {
283 $formatted['network'] = strip_tags( $v['Network'] );
284 }
285 if ( isset( $v['PluginURI'] ) ) {
286 $formatted['plugin_uri'] = strip_tags( $v['PluginURI'] );
287 }
288 if ( in_array( $k, $active_plugins_keys ) ) {
289 // Remove active plugins from list so we can show active and inactive separately.
290 unset( $plugins[ $k ] );
291 $active_plugins[ $k ] = $formatted;
292 } else {
293 $plugins[ $k ] = $formatted;
294 }
295 }
296
297 return array(
298 'active_plugins' => $active_plugins,
299 'inactive_plugins' => $plugins,
300 );
301 }
302
303 /**
304 * Check to see if the helper is connected to woocommerce.com
305 *
306 * @return string
307 */
308 private static function get_helper_connected() {
309 if ( class_exists( 'WC_Helper_Options' ) && is_callable( 'WC_Helper_Options::get' ) ) {
310 $authenticated = WC_Helper_Options::get( 'auth' );
311 } else {
312 $authenticated = '';
313 }
314 return ( ! empty( $authenticated ) ) ? 'yes' : 'no';
315 }
316
317
318 /**
319 * Get user totals based on user role.
320 *
321 * @return array
322 */
323 private static function get_user_counts() {
324 $user_count = array();
325 $user_count_data = count_users();
326 $user_count['total'] = $user_count_data['total_users'];
327
328 // Get user count based on user role.
329 foreach ( $user_count_data['avail_roles'] as $role => $count ) {
330 $user_count[ $role ] = $count;
331 }
332
333 return $user_count;
334 }
335
336 /**
337 * Get product totals based on product type.
338 *
339 * @return array
340 */
341 public static function get_product_counts() {
342 $product_count = array();
343 $product_count_data = wp_count_posts( 'product' );
344 $product_count['total'] = $product_count_data->publish;
345
346 $product_statuses = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
347 foreach ( $product_statuses as $product_status ) {
348 $product_count[ $product_status->name ] = $product_status->count;
349 }
350
351 return $product_count;
352 }
353
354 /**
355 * Get order counts
356 *
357 * @return array
358 */
359 private static function get_order_counts() {
360 $order_count = array();
361 $order_count_data = wp_count_posts( 'shop_order' );
362 foreach ( wc_get_order_statuses() as $status_slug => $status_name ) {
363 $order_count[ $status_slug ] = $order_count_data->{ $status_slug };
364 }
365 return $order_count;
366 }
367
368 /**
369 * Combine all order data.
370 *
371 * @return array
372 */
373 private static function get_orders() {
374 $order_dates = self::get_order_dates();
375 $order_counts = self::get_order_counts();
376 $order_totals = self::get_order_totals();
377
378 return array_merge( $order_dates, $order_counts, $order_totals );
379 }
380
381 /**
382 * Get review counts for different statuses.
383 *
384 * @return array
385 */
386 private static function get_review_counts() {
387 global $wpdb;
388 $review_count = array( 'total' => 0 );
389 $status_map = array(
390 '0' => 'pending',
391 '1' => 'approved',
392 'trash' => 'trash',
393 'spam' => 'spam',
394 );
395 $counts = $wpdb->get_results(
396 "
397 SELECT comment_approved, COUNT(*) AS num_reviews
398 FROM {$wpdb->comments}
399 WHERE comment_type = 'review'
400 GROUP BY comment_approved
401 ",
402 ARRAY_A
403 );
404
405 if ( ! $counts ) {
406 return $review_count;
407 }
408
409 foreach ( $counts as $count ) {
410 $status = $count['comment_approved'];
411 if ( array_key_exists( $status, $status_map ) ) {
412 $review_count[ $status_map[ $status ] ] = $count['num_reviews'];
413 }
414 $review_count['total'] += $count['num_reviews'];
415 }
416
417 return $review_count;
418 }
419
420 /**
421 * Get the number of product categories.
422 *
423 * @return int
424 */
425 private static function get_category_counts() {
426 return wp_count_terms( 'product_cat' );
427 }
428
429 /**
430 * Get a list of all active payment gateways.
431 *
432 * @return array
433 */
434 private static function get_active_payment_gateways() {
435 $active_gateways = array();
436 $gateways = WC()->payment_gateways->payment_gateways();
437 foreach ( $gateways as $id => $gateway ) {
438 if ( isset( $gateway->enabled ) && 'yes' === $gateway->enabled ) {
439 $active_gateways[ $id ] = array(
440 'title' => $gateway->title,
441 'supports' => $gateway->supports,
442 );
443 }
444 }
445
446 return $active_gateways;
447 }
448
449 /**
450 * Get a list of all active shipping methods.
451 *
452 * @return array
453 */
454 private static function get_active_shipping_methods() {
455 $active_methods = array();
456 $shipping_methods = WC()->shipping()->get_shipping_methods();
457 foreach ( $shipping_methods as $id => $shipping_method ) {
458 if ( isset( $shipping_method->enabled ) && 'yes' === $shipping_method->enabled ) {
459 $active_methods[ $id ] = array(
460 'title' => $shipping_method->title,
461 'tax_status' => $shipping_method->tax_status,
462 );
463 }
464 }
465
466 return $active_methods;
467 }
468
469 /**
470 * Get all options starting with woocommerce_ prefix.
471 *
472 * @return array
473 */
474 private static function get_all_woocommerce_options_values() {
475 return array(
476 'version' => WC()->version,
477 'currency' => get_woocommerce_currency(),
478 'base_location' => WC()->countries->get_base_country(),
479 'selling_locations' => WC()->countries->get_allowed_countries(),
480 'api_enabled' => get_option( 'woocommerce_api_enabled' ),
481 'weight_unit' => get_option( 'woocommerce_weight_unit' ),
482 'dimension_unit' => get_option( 'woocommerce_dimension_unit' ),
483 'download_method' => get_option( 'woocommerce_file_download_method' ),
484 'download_require_login' => get_option( 'woocommerce_downloads_require_login' ),
485 'calc_taxes' => get_option( 'woocommerce_calc_taxes' ),
486 'coupons_enabled' => get_option( 'woocommerce_enable_coupons' ),
487 'guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
488 'secure_checkout' => get_option( 'woocommerce_force_ssl_checkout' ),
489 'enable_signup_and_login_from_checkout' => get_option( 'woocommerce_enable_signup_and_login_from_checkout' ),
490 'enable_myaccount_registration' => get_option( 'woocommerce_enable_myaccount_registration' ),
491 'registration_generate_username' => get_option( 'woocommerce_registration_generate_username' ),
492 'registration_generate_password' => get_option( 'woocommerce_registration_generate_password' ),
493 );
494 }
495
496 /**
497 * Look for any template override and return filenames.
498 *
499 * @return array
500 */
501 private static function get_all_template_overrides() {
502 $override_data = array();
503 $template_paths = apply_filters( 'woocommerce_template_overrides_scan_paths', array( 'WooCommerce' => WC()->plugin_path() . '/templates/' ) );
504 $scanned_files = array();
505
506 require_once WC()->plugin_path() . '/includes/admin/class-wc-admin-status.php';
507
508 foreach ( $template_paths as $plugin_name => $template_path ) {
509 $scanned_files[ $plugin_name ] = WC_Admin_Status::scan_template_files( $template_path );
510 }
511
512 foreach ( $scanned_files as $plugin_name => $files ) {
513 foreach ( $files as $file ) {
514 if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
515 $theme_file = get_stylesheet_directory() . '/' . $file;
516 } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) {
517 $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file;
518 } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
519 $theme_file = get_template_directory() . '/' . $file;
520 } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) {
521 $theme_file = get_template_directory() . '/' . WC()->template_path() . $file;
522 } else {
523 $theme_file = false;
524 }
525
526 if ( false !== $theme_file ) {
527 $override_data[] = basename( $theme_file );
528 }
529 }
530 }
531 return $override_data;
532 }
533
534 /**
535 * When an admin user logs in, there user agent is tracked in user meta and collected here.
536 *
537 * @return array
538 */
539 private static function get_admin_user_agents() {
540 return array_filter( (array) get_option( 'woocommerce_tracker_ua', array() ) );
541 }
542
543 /**
544 * Get order totals
545 *
546 * @return array
547 */
548 public static function get_order_totals() {
549 global $wpdb;
550
551 $gross_total = $wpdb->get_var(
552 "
553 SELECT
554 SUM( order_meta.meta_value ) AS 'gross_total'
555 FROM {$wpdb->prefix}posts AS orders
556 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
557 WHERE order_meta.meta_key = '_order_total'
558 AND orders.post_status in ( 'wc-completed', 'wc-refunded' )
559 GROUP BY order_meta.meta_key
560 "
561 );
562
563 if ( is_null( $gross_total ) ) {
564 $gross_total = 0;
565 }
566
567 $processing_gross_total = $wpdb->get_var(
568 "
569 SELECT
570 SUM( order_meta.meta_value ) AS 'gross_total'
571 FROM {$wpdb->prefix}posts AS orders
572 LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID
573 WHERE order_meta.meta_key = '_order_total'
574 AND orders.post_status = 'wc-processing'
575 GROUP BY order_meta.meta_key
576 "
577 );
578
579 if ( is_null( $processing_gross_total ) ) {
580 $processing_gross_total = 0;
581 }
582
583 return array(
584 'gross' => $gross_total,
585 'processing_gross' => $processing_gross_total,
586 );
587 }
588
589 /**
590 * Get last order date
591 *
592 * @return string
593 */
594 private static function get_order_dates() {
595 global $wpdb;
596
597 $min_max = $wpdb->get_row(
598 "
599 SELECT
600 MIN( post_date_gmt ) as 'first', MAX( post_date_gmt ) as 'last'
601 FROM {$wpdb->prefix}posts
602 WHERE post_type = 'shop_order'
603 AND post_status = 'wc-completed'
604 ",
605 ARRAY_A
606 );
607
608 if ( is_null( $min_max ) ) {
609 $min_max = array(
610 'first' => '-',
611 'last' => '-',
612 );
613 }
614
615 $processing_min_max = $wpdb->get_row(
616 "
617 SELECT
618 MIN( post_date_gmt ) as 'processing_first', MAX( post_date_gmt ) as 'processing_last'
619 FROM {$wpdb->prefix}posts
620 WHERE post_type = 'shop_order'
621 AND post_status = 'wc-processing'
622 ",
623 ARRAY_A
624 );
625
626 if ( is_null( $processing_min_max ) ) {
627 $processing_min_max = array(
628 'processing_first' => '-',
629 'processing_last' => '-',
630 );
631 }
632
633 return array_merge( $min_max, $processing_min_max );
634 }
635
636 /**
637 * Search a specific post for text content.
638 *
639 * @param integer $post_id The id of the post to search.
640 * @param string $text The text to search for.
641 * @return string 'Yes' if post contains $text (otherwise 'No').
642 */
643 public static function post_contains_text( $post_id, $text ) {
644 global $wpdb;
645
646 // Search for the text anywhere in the post.
647 $wildcarded = "%{$text}%";
648
649 $result = $wpdb->get_var(
650 $wpdb->prepare(
651 "
652 SELECT COUNT( * ) FROM {$wpdb->prefix}posts
653 WHERE ID=%d
654 AND {$wpdb->prefix}posts.post_content LIKE %s
655 ",
656 array( $post_id, $wildcarded )
657 )
658 );
659
660 return ( '0' !== $result ) ? 'Yes' : 'No';
661 }
662
663 /**
664 * Get blocks from a woocommerce page.
665 *
666 * @param string $woo_page_name A woocommerce page e.g. `checkout` or `cart`.
667 * @return array Array of blocks as returned by parse_blocks().
668 */
669 private static function get_all_blocks_from_page( $woo_page_name ) {
670 $page_id = wc_get_page_id( $woo_page_name );
671
672 $page = get_post( $page_id );
673 if ( ! $page ) {
674 return array();
675 }
676
677 $blocks = parse_blocks( $page->post_content );
678 if ( ! $blocks ) {
679 return array();
680 }
681
682 return $blocks;
683 }
684
685 /**
686 * Get all instances of the specified block on a specific woo page
687 * (e.g. `cart` or `checkout` page).
688 *
689 * @param string $block_name The name (id) of a block, e.g. `woocommerce/cart`.
690 * @param string $woo_page_name The woo page to search, e.g. `cart`.
691 * @return array Array of blocks as returned by parse_blocks().
692 */
693 private static function get_blocks_from_page( $block_name, $woo_page_name ) {
694 $page_blocks = self::get_all_blocks_from_page( $woo_page_name );
695
696 // Get any instances of the specified block.
697 return array_values(
698 array_filter(
699 $page_blocks,
700 function ( $block ) use ( $block_name ) {
701 return ( $block_name === $block['blockName'] );
702 }
703 )
704 );
705 }
706
707 /**
708 * Get tracker data for a specific block type on a woocommerce page.
709 *
710 * @param string $block_name The name (id) of a block, e.g. `woocommerce/cart`.
711 * @param string $woo_page_name The woo page to search, e.g. `cart`.
712 * @return array Associative array of tracker data with keys:
713 * - page_contains_block
714 * - block_attributes
715 */
716 public static function get_block_tracker_data( $block_name, $woo_page_name ) {
717 $blocks = self::get_blocks_from_page( $block_name, $woo_page_name );
718
719 $block_present = false;
720 $attributes = array();
721 if ( $blocks && count( $blocks ) ) {
722 // Return any customised attributes from the first block.
723 $block_present = true;
724 $attributes = $blocks[0]['attrs'];
725 }
726
727 return array(
728 'page_contains_block' => $block_present ? 'Yes' : 'No',
729 'block_attributes' => $attributes,
730 );
731 }
732
733 /**
734 * Get info about the cart & checkout pages.
735 *
736 * @return array
737 */
738 public static function get_cart_checkout_info() {
739 $cart_page_id = wc_get_page_id( 'cart' );
740 $checkout_page_id = wc_get_page_id( 'checkout' );
741
742 $cart_block_data = self::get_block_tracker_data( 'woocommerce/cart', 'cart' );
743 $checkout_block_data = self::get_block_tracker_data( 'woocommerce/checkout', 'checkout' );
744
745 return array(
746 'cart_page_contains_cart_shortcode' => self::post_contains_text(
747 $cart_page_id,
748 '[woocommerce_cart]'
749 ),
750 'checkout_page_contains_checkout_shortcode' => self::post_contains_text(
751 $checkout_page_id,
752 '[woocommerce_checkout]'
753 ),
754
755 'cart_page_contains_cart_block' => $cart_block_data['page_contains_block'],
756 'cart_block_attributes' => $cart_block_data['block_attributes'],
757 'checkout_page_contains_checkout_block' => $checkout_block_data['page_contains_block'],
758 'checkout_block_attributes' => $checkout_block_data['block_attributes'],
759 );
760 }
761 }
762
763 WC_Tracker::init();
764