abstracts
7 years ago
admin
7 years ago
api
7 years ago
cli
7 years ago
customizer
7 years ago
data-stores
7 years ago
emails
7 years ago
export
7 years ago
gateways
7 years ago
import
7 years ago
interfaces
7 years ago
legacy
7 years ago
libraries
7 years ago
log-handlers
7 years ago
payment-tokens
7 years ago
queue
7 years ago
shipping
7 years ago
shortcodes
7 years ago
theme-support
7 years ago
walkers
7 years ago
widgets
7 years ago
class-wc-ajax.php
7 years ago
class-wc-api.php
7 years ago
class-wc-auth.php
7 years ago
class-wc-autoloader.php
7 years ago
class-wc-background-emailer.php
7 years ago
class-wc-background-updater.php
7 years ago
class-wc-breadcrumb.php
7 years ago
class-wc-cache-helper.php
7 years ago
class-wc-cart-fees.php
7 years ago
class-wc-cart-session.php
7 years ago
class-wc-cart-totals.php
7 years ago
class-wc-cart.php
7 years ago
class-wc-checkout.php
7 years ago
class-wc-cli.php
7 years ago
class-wc-comments.php
7 years ago
class-wc-countries.php
7 years ago
class-wc-coupon.php
7 years ago
class-wc-customer-download-log.php
7 years ago
class-wc-customer-download.php
7 years ago
class-wc-customer.php
7 years ago
class-wc-data-exception.php
7 years ago
class-wc-data-store.php
7 years ago
class-wc-datetime.php
7 years ago
class-wc-deprecated-action-hooks.php
7 years ago
class-wc-deprecated-filter-hooks.php
7 years ago
class-wc-discounts.php
7 years ago
class-wc-download-handler.php
7 years ago
class-wc-emails.php
7 years ago
class-wc-embed.php
7 years ago
class-wc-form-handler.php
7 years ago
class-wc-frontend-scripts.php
7 years ago
class-wc-geo-ip.php
7 years ago
class-wc-geolite-integration.php
7 years ago
class-wc-geolocation.php
7 years ago
class-wc-https.php
7 years ago
class-wc-install.php
7 years ago
class-wc-integrations.php
7 years ago
class-wc-log-levels.php
7 years ago
class-wc-logger.php
7 years ago
class-wc-meta-data.php
7 years ago
class-wc-order-factory.php
7 years ago
class-wc-order-item-coupon.php
7 years ago
class-wc-order-item-fee.php
7 years ago
class-wc-order-item-meta.php
7 years ago
class-wc-order-item-product.php
7 years ago
class-wc-order-item-shipping.php
7 years ago
class-wc-order-item-tax.php
7 years ago
class-wc-order-item.php
7 years ago
class-wc-order-query.php
7 years ago
class-wc-order-refund.php
7 years ago
class-wc-order.php
7 years ago
class-wc-payment-gateways.php
7 years ago
class-wc-payment-tokens.php
7 years ago
class-wc-post-data.php
7 years ago
class-wc-post-types.php
7 years ago
class-wc-privacy-background-process.php
7 years ago
class-wc-privacy-erasers.php
7 years ago
class-wc-privacy-exporters.php
7 years ago
class-wc-privacy.php
7 years ago
class-wc-product-attribute.php
7 years ago
class-wc-product-download.php
7 years ago
class-wc-product-external.php
7 years ago
class-wc-product-factory.php
7 years ago
class-wc-product-grouped.php
7 years ago
class-wc-product-query.php
7 years ago
class-wc-product-simple.php
7 years ago
class-wc-product-variable.php
7 years ago
class-wc-product-variation.php
7 years ago
class-wc-query.php
7 years ago
class-wc-regenerate-images-request.php
7 years ago
class-wc-regenerate-images.php
7 years ago
class-wc-register-wp-admin-settings.php
7 years ago
class-wc-session-handler.php
7 years ago
class-wc-shipping-rate.php
7 years ago
class-wc-shipping-zone.php
7 years ago
class-wc-shipping-zones.php
7 years ago
class-wc-shipping.php
7 years ago
class-wc-shortcodes.php
7 years ago
class-wc-structured-data.php
7 years ago
class-wc-tax.php
7 years ago
class-wc-template-loader.php
7 years ago
class-wc-tracker.php
7 years ago
class-wc-validation.php
7 years ago
class-wc-webhook.php
7 years ago
class-woocommerce.php
7 years ago
wc-account-functions.php
7 years ago
wc-attribute-functions.php
7 years ago
wc-cart-functions.php
7 years ago
wc-conditional-functions.php
7 years ago
wc-core-functions.php
7 years ago
wc-coupon-functions.php
7 years ago
wc-deprecated-functions.php
7 years ago
wc-formatting-functions.php
7 years ago
wc-notice-functions.php
7 years ago
wc-order-functions.php
7 years ago
wc-order-item-functions.php
7 years ago
wc-page-functions.php
7 years ago
wc-product-functions.php
7 years ago
wc-rest-functions.php
7 years ago
wc-stock-functions.php
7 years ago
wc-template-functions.php
7 years ago
wc-template-hooks.php
7 years ago
wc-term-functions.php
7 years ago
wc-update-functions.php
7 years ago
wc-user-functions.php
7 years ago
wc-webhook-functions.php
7 years ago
wc-widget-functions.php
7 years ago
class-wc-tracker.php
568 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 | defined( 'ABSPATH' ) || exit; |
| 14 | |
| 15 | /** |
| 16 | * WooCommerce Tracker Class |
| 17 | */ |
| 18 | class WC_Tracker { |
| 19 | |
| 20 | /** |
| 21 | * URL to the WooThemes Tracker API endpoint. |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | private static $api_url = 'https://tracking.woocommerce.com/v1/'; |
| 26 | |
| 27 | /** |
| 28 | * Hook into cron event. |
| 29 | */ |
| 30 | public static function init() { |
| 31 | add_action( 'woocommerce_tracker_send_event', array( __CLASS__, 'send_tracking_data' ) ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Decide whether to send tracking data or not. |
| 36 | * |
| 37 | * @param boolean $override Should override?. |
| 38 | */ |
| 39 | public static function send_tracking_data( $override = false ) { |
| 40 | // Don't trigger this on AJAX Requests. |
| 41 | if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | if ( ! apply_filters( 'woocommerce_tracker_send_override', $override ) ) { |
| 46 | // Send a maximum of once per week by default. |
| 47 | $last_send = self::get_last_send_time(); |
| 48 | if ( $last_send && $last_send > apply_filters( 'woocommerce_tracker_last_send_interval', strtotime( '-1 week' ) ) ) { |
| 49 | return; |
| 50 | } |
| 51 | } else { |
| 52 | // Make sure there is at least a 1 hour delay between override sends, we don't want duplicate calls due to double clicking links. |
| 53 | $last_send = self::get_last_send_time(); |
| 54 | if ( $last_send && $last_send > strtotime( '-1 hours' ) ) { |
| 55 | return; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Update time first before sending to ensure it is set. |
| 60 | update_option( 'woocommerce_tracker_last_send', time() ); |
| 61 | |
| 62 | $params = self::get_tracking_data(); |
| 63 | wp_safe_remote_post( self::$api_url, array( |
| 64 | 'method' => 'POST', |
| 65 | 'timeout' => 45, |
| 66 | 'redirection' => 5, |
| 67 | 'httpversion' => '1.0', |
| 68 | 'blocking' => false, |
| 69 | 'headers' => array( 'user-agent' => 'WooCommerceTracker/' . md5( esc_url_raw( home_url( '/' ) ) ) . ';' ), |
| 70 | 'body' => wp_json_encode( $params ), |
| 71 | 'cookies' => array(), |
| 72 | ) ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Get the last time tracking data was sent. |
| 77 | * |
| 78 | * @return int|bool |
| 79 | */ |
| 80 | private static function get_last_send_time() { |
| 81 | return apply_filters( 'woocommerce_tracker_last_send_time', get_option( 'woocommerce_tracker_last_send', false ) ); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Get all the tracking data. |
| 86 | * |
| 87 | * @return array |
| 88 | */ |
| 89 | private static function get_tracking_data() { |
| 90 | $data = array(); |
| 91 | |
| 92 | // General site info. |
| 93 | $data['url'] = home_url(); |
| 94 | $data['email'] = apply_filters( 'woocommerce_tracker_admin_email', get_option( 'admin_email' ) ); |
| 95 | $data['theme'] = self::get_theme_info(); |
| 96 | |
| 97 | // WordPress Info. |
| 98 | $data['wp'] = self::get_wordpress_info(); |
| 99 | |
| 100 | // Server Info. |
| 101 | $data['server'] = self::get_server_info(); |
| 102 | |
| 103 | // Plugin info. |
| 104 | $all_plugins = self::get_all_plugins(); |
| 105 | $data['active_plugins'] = $all_plugins['active_plugins']; |
| 106 | $data['inactive_plugins'] = $all_plugins['inactive_plugins']; |
| 107 | |
| 108 | // Jetpack & WooCommerce Connect. |
| 109 | $data['jetpack_version'] = defined( 'JETPACK__VERSION' ) ? JETPACK__VERSION : 'none'; |
| 110 | $data['jetpack_connected'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_active' ) && Jetpack::is_active() ) ? 'yes' : 'no'; |
| 111 | $data['jetpack_is_staging'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_staging_site' ) && Jetpack::is_staging_site() ) ? 'yes' : 'no'; |
| 112 | $data['connect_installed'] = class_exists( 'WC_Connect_Loader' ) ? 'yes' : 'no'; |
| 113 | $data['connect_active'] = ( class_exists( 'WC_Connect_Loader' ) && wp_next_scheduled( 'wc_connect_fetch_service_schemas' ) ) ? 'yes' : 'no'; |
| 114 | $data['helper_connected'] = self::get_helper_connected(); |
| 115 | |
| 116 | // Store count info. |
| 117 | $data['users'] = self::get_user_counts(); |
| 118 | $data['products'] = self::get_product_counts(); |
| 119 | $data['orders'] = self::get_orders(); |
| 120 | $data['reviews'] = self::get_review_counts(); |
| 121 | $data['categories'] = self::get_category_counts(); |
| 122 | |
| 123 | // Payment gateway info. |
| 124 | $data['gateways'] = self::get_active_payment_gateways(); |
| 125 | |
| 126 | // Shipping method info. |
| 127 | $data['shipping_methods'] = self::get_active_shipping_methods(); |
| 128 | |
| 129 | // Get all WooCommerce options info. |
| 130 | $data['settings'] = self::get_all_woocommerce_options_values(); |
| 131 | |
| 132 | // Template overrides. |
| 133 | $data['template_overrides'] = self::get_all_template_overrides(); |
| 134 | |
| 135 | // Template overrides. |
| 136 | $data['admin_user_agents'] = self::get_admin_user_agents(); |
| 137 | |
| 138 | return apply_filters( 'woocommerce_tracker_data', $data ); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Get the current theme info, theme name and version. |
| 143 | * |
| 144 | * @return array |
| 145 | */ |
| 146 | public static function get_theme_info() { |
| 147 | $theme_data = wp_get_theme(); |
| 148 | $theme_child_theme = wc_bool_to_string( is_child_theme() ); |
| 149 | $theme_wc_support = wc_bool_to_string( current_theme_supports( 'woocommerce' ) ); |
| 150 | |
| 151 | return array( |
| 152 | 'name' => $theme_data->Name, // @phpcs:ignore |
| 153 | 'version' => $theme_data->Version, // @phpcs:ignore |
| 154 | 'child_theme' => $theme_child_theme, |
| 155 | 'wc_support' => $theme_wc_support, |
| 156 | ); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Get WordPress related data. |
| 161 | * |
| 162 | * @return array |
| 163 | */ |
| 164 | private static function get_wordpress_info() { |
| 165 | $wp_data = array(); |
| 166 | |
| 167 | $memory = wc_let_to_num( WP_MEMORY_LIMIT ); |
| 168 | |
| 169 | if ( function_exists( 'memory_get_usage' ) ) { |
| 170 | $system_memory = wc_let_to_num( @ini_get( 'memory_limit' ) ); |
| 171 | $memory = max( $memory, $system_memory ); |
| 172 | } |
| 173 | |
| 174 | $wp_data['memory_limit'] = size_format( $memory ); |
| 175 | $wp_data['debug_mode'] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No'; |
| 176 | $wp_data['locale'] = get_locale(); |
| 177 | $wp_data['version'] = get_bloginfo( 'version' ); |
| 178 | $wp_data['multisite'] = is_multisite() ? 'Yes' : 'No'; |
| 179 | |
| 180 | return $wp_data; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Get server related info. |
| 185 | * |
| 186 | * @return array |
| 187 | */ |
| 188 | private static function get_server_info() { |
| 189 | $server_data = array(); |
| 190 | |
| 191 | if ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) { |
| 192 | $server_data['software'] = $_SERVER['SERVER_SOFTWARE']; // @phpcs:ignore |
| 193 | } |
| 194 | |
| 195 | if ( function_exists( 'phpversion' ) ) { |
| 196 | $server_data['php_version'] = phpversion(); |
| 197 | } |
| 198 | |
| 199 | if ( function_exists( 'ini_get' ) ) { |
| 200 | $server_data['php_post_max_size'] = size_format( wc_let_to_num( ini_get( 'post_max_size' ) ) ); |
| 201 | $server_data['php_time_limt'] = ini_get( 'max_execution_time' ); |
| 202 | $server_data['php_max_input_vars'] = ini_get( 'max_input_vars' ); |
| 203 | $server_data['php_suhosin'] = extension_loaded( 'suhosin' ) ? 'Yes' : 'No'; |
| 204 | } |
| 205 | |
| 206 | $database_version = wc_get_server_database_version(); |
| 207 | $server_data['mysql_version'] = $database_version['number']; |
| 208 | |
| 209 | $server_data['php_max_upload_size'] = size_format( wp_max_upload_size() ); |
| 210 | $server_data['php_default_timezone'] = date_default_timezone_get(); |
| 211 | $server_data['php_soap'] = class_exists( 'SoapClient' ) ? 'Yes' : 'No'; |
| 212 | $server_data['php_fsockopen'] = function_exists( 'fsockopen' ) ? 'Yes' : 'No'; |
| 213 | $server_data['php_curl'] = function_exists( 'curl_init' ) ? 'Yes' : 'No'; |
| 214 | |
| 215 | return $server_data; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Get all plugins grouped into activated or not. |
| 220 | * |
| 221 | * @return array |
| 222 | */ |
| 223 | private static function get_all_plugins() { |
| 224 | // Ensure get_plugins function is loaded. |
| 225 | if ( ! function_exists( 'get_plugins' ) ) { |
| 226 | include ABSPATH . '/wp-admin/includes/plugin.php'; |
| 227 | } |
| 228 | |
| 229 | $plugins = get_plugins(); |
| 230 | $active_plugins_keys = get_option( 'active_plugins', array() ); |
| 231 | $active_plugins = array(); |
| 232 | |
| 233 | foreach ( $plugins as $k => $v ) { |
| 234 | // Take care of formatting the data how we want it. |
| 235 | $formatted = array(); |
| 236 | $formatted['name'] = strip_tags( $v['Name'] ); |
| 237 | if ( isset( $v['Version'] ) ) { |
| 238 | $formatted['version'] = strip_tags( $v['Version'] ); |
| 239 | } |
| 240 | if ( isset( $v['Author'] ) ) { |
| 241 | $formatted['author'] = strip_tags( $v['Author'] ); |
| 242 | } |
| 243 | if ( isset( $v['Network'] ) ) { |
| 244 | $formatted['network'] = strip_tags( $v['Network'] ); |
| 245 | } |
| 246 | if ( isset( $v['PluginURI'] ) ) { |
| 247 | $formatted['plugin_uri'] = strip_tags( $v['PluginURI'] ); |
| 248 | } |
| 249 | if ( in_array( $k, $active_plugins_keys ) ) { |
| 250 | // Remove active plugins from list so we can show active and inactive separately. |
| 251 | unset( $plugins[ $k ] ); |
| 252 | $active_plugins[ $k ] = $formatted; |
| 253 | } else { |
| 254 | $plugins[ $k ] = $formatted; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return array( |
| 259 | 'active_plugins' => $active_plugins, |
| 260 | 'inactive_plugins' => $plugins, |
| 261 | ); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Check to see if the helper is connected to woocommerce.com |
| 266 | * |
| 267 | * @return string |
| 268 | */ |
| 269 | private static function get_helper_connected() { |
| 270 | if ( class_exists( 'WC_Helper_Options' ) && is_callable( 'WC_Helper_Options::get' ) ) { |
| 271 | $authenticated = WC_Helper_Options::get( 'auth' ); |
| 272 | } else { |
| 273 | $authenticated = ''; |
| 274 | } |
| 275 | return ( ! empty( $authenticated ) ) ? 'yes' : 'no'; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | /** |
| 280 | * Get user totals based on user role. |
| 281 | * |
| 282 | * @return array |
| 283 | */ |
| 284 | private static function get_user_counts() { |
| 285 | $user_count = array(); |
| 286 | $user_count_data = count_users(); |
| 287 | $user_count['total'] = $user_count_data['total_users']; |
| 288 | |
| 289 | // Get user count based on user role. |
| 290 | foreach ( $user_count_data['avail_roles'] as $role => $count ) { |
| 291 | $user_count[ $role ] = $count; |
| 292 | } |
| 293 | |
| 294 | return $user_count; |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Get product totals based on product type. |
| 299 | * |
| 300 | * @return array |
| 301 | */ |
| 302 | private static function get_product_counts() { |
| 303 | $product_count = array(); |
| 304 | $product_count_data = wp_count_posts( 'product' ); |
| 305 | $product_count['total'] = $product_count_data->publish; |
| 306 | |
| 307 | $product_statuses = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); |
| 308 | foreach ( $product_statuses as $product_status ) { |
| 309 | $product_count[ $product_status->name ] = $product_status->count; |
| 310 | } |
| 311 | |
| 312 | return $product_count; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Get order counts |
| 317 | * |
| 318 | * @return array |
| 319 | */ |
| 320 | private static function get_order_counts() { |
| 321 | $order_count = array(); |
| 322 | $order_count_data = wp_count_posts( 'shop_order' ); |
| 323 | foreach ( wc_get_order_statuses() as $status_slug => $status_name ) { |
| 324 | $order_count[ $status_slug ] = $order_count_data->{ $status_slug }; |
| 325 | } |
| 326 | return $order_count; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Combine all order data. |
| 331 | * |
| 332 | * @return array |
| 333 | */ |
| 334 | private static function get_orders() { |
| 335 | $order_dates = self::get_order_dates(); |
| 336 | $order_counts = self::get_order_counts(); |
| 337 | $order_totals = self::get_order_totals(); |
| 338 | |
| 339 | return array_merge( $order_dates, $order_counts, $order_totals ); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Get review counts for different statuses. |
| 344 | * |
| 345 | * @return array |
| 346 | */ |
| 347 | private static function get_review_counts() { |
| 348 | global $wpdb; |
| 349 | $review_count = array(); |
| 350 | $counts = $wpdb->get_results( " |
| 351 | SELECT comment_approved, COUNT(*) AS num_reviews |
| 352 | FROM {$wpdb->comments} |
| 353 | WHERE comment_type = 'review' |
| 354 | GROUP BY comment_approved |
| 355 | ", ARRAY_A ); |
| 356 | if ( $counts ) { |
| 357 | foreach ( $counts as $count ) { |
| 358 | if ( 1 === $count['comment_approved'] ) { |
| 359 | $review_count['approved'] = $count['num_reviews']; |
| 360 | } else { |
| 361 | $review_count['pending'] = $count['num_reviews']; |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | return $review_count; |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Get the number of product categories. |
| 370 | * |
| 371 | * @return int |
| 372 | */ |
| 373 | private static function get_category_counts() { |
| 374 | return wp_count_terms( 'product_cat' ); |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Get a list of all active payment gateways. |
| 379 | * |
| 380 | * @return array |
| 381 | */ |
| 382 | private static function get_active_payment_gateways() { |
| 383 | $active_gateways = array(); |
| 384 | $gateways = WC()->payment_gateways->payment_gateways(); |
| 385 | foreach ( $gateways as $id => $gateway ) { |
| 386 | if ( isset( $gateway->enabled ) && 'yes' === $gateway->enabled ) { |
| 387 | $active_gateways[ $id ] = array( |
| 388 | 'title' => $gateway->title, |
| 389 | 'supports' => $gateway->supports, |
| 390 | ); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | return $active_gateways; |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Get a list of all active shipping methods. |
| 399 | * |
| 400 | * @return array |
| 401 | */ |
| 402 | private static function get_active_shipping_methods() { |
| 403 | $active_methods = array(); |
| 404 | $shipping_methods = WC()->shipping->get_shipping_methods(); |
| 405 | foreach ( $shipping_methods as $id => $shipping_method ) { |
| 406 | if ( isset( $shipping_method->enabled ) && 'yes' === $shipping_method->enabled ) { |
| 407 | $active_methods[ $id ] = array( |
| 408 | 'title' => $shipping_method->title, |
| 409 | 'tax_status' => $shipping_method->tax_status, |
| 410 | ); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | return $active_methods; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Get all options starting with woocommerce_ prefix. |
| 419 | * |
| 420 | * @return array |
| 421 | */ |
| 422 | private static function get_all_woocommerce_options_values() { |
| 423 | return array( |
| 424 | 'version' => WC()->version, |
| 425 | 'currency' => get_woocommerce_currency(), |
| 426 | 'base_location' => WC()->countries->get_base_country(), |
| 427 | 'selling_locations' => WC()->countries->get_allowed_countries(), |
| 428 | 'api_enabled' => get_option( 'woocommerce_api_enabled' ), |
| 429 | 'weight_unit' => get_option( 'woocommerce_weight_unit' ), |
| 430 | 'dimension_unit' => get_option( 'woocommerce_dimension_unit' ), |
| 431 | 'download_method' => get_option( 'woocommerce_file_download_method' ), |
| 432 | 'download_require_login' => get_option( 'woocommerce_downloads_require_login' ), |
| 433 | 'calc_taxes' => get_option( 'woocommerce_calc_taxes' ), |
| 434 | 'coupons_enabled' => get_option( 'woocommerce_enable_coupons' ), |
| 435 | 'guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ), |
| 436 | 'secure_checkout' => get_option( 'woocommerce_force_ssl_checkout' ), |
| 437 | 'enable_signup_and_login_from_checkout' => get_option( 'woocommerce_enable_signup_and_login_from_checkout' ), |
| 438 | 'enable_myaccount_registration' => get_option( 'woocommerce_enable_myaccount_registration' ), |
| 439 | 'registration_generate_username' => get_option( 'woocommerce_registration_generate_username' ), |
| 440 | 'registration_generate_password' => get_option( 'woocommerce_registration_generate_password' ), |
| 441 | ); |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Look for any template override and return filenames. |
| 446 | * |
| 447 | * @return array |
| 448 | */ |
| 449 | private static function get_all_template_overrides() { |
| 450 | $override_data = array(); |
| 451 | $template_paths = apply_filters( 'woocommerce_template_overrides_scan_paths', array( 'WooCommerce' => WC()->plugin_path() . '/templates/' ) ); |
| 452 | $scanned_files = array(); |
| 453 | |
| 454 | require_once( WC()->plugin_path() . '/includes/admin/class-wc-admin-status.php' ); |
| 455 | |
| 456 | foreach ( $template_paths as $plugin_name => $template_path ) { |
| 457 | $scanned_files[ $plugin_name ] = WC_Admin_Status::scan_template_files( $template_path ); |
| 458 | } |
| 459 | |
| 460 | foreach ( $scanned_files as $plugin_name => $files ) { |
| 461 | foreach ( $files as $file ) { |
| 462 | if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
| 463 | $theme_file = get_stylesheet_directory() . '/' . $file; |
| 464 | } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) { |
| 465 | $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file; |
| 466 | } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { |
| 467 | $theme_file = get_template_directory() . '/' . $file; |
| 468 | } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) { |
| 469 | $theme_file = get_template_directory() . '/' . WC()->template_path() . $file; |
| 470 | } else { |
| 471 | $theme_file = false; |
| 472 | } |
| 473 | |
| 474 | if ( false !== $theme_file ) { |
| 475 | $override_data[] = basename( $theme_file ); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | return $override_data; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * When an admin user logs in, there user agent is tracked in user meta and collected here. |
| 484 | * |
| 485 | * @return array |
| 486 | */ |
| 487 | private static function get_admin_user_agents() { |
| 488 | return array_filter( (array) get_option( 'woocommerce_tracker_ua', array() ) ); |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Get order totals |
| 493 | * |
| 494 | * @return array |
| 495 | */ |
| 496 | private static function get_order_totals() { |
| 497 | global $wpdb; |
| 498 | |
| 499 | $gross_total = $wpdb->get_var( " |
| 500 | SELECT |
| 501 | SUM( order_meta.meta_value ) AS 'gross_total' |
| 502 | FROM {$wpdb->prefix}posts AS orders |
| 503 | LEFT JOIN {$wpdb->prefix}postmeta AS order_meta ON order_meta.post_id = orders.ID |
| 504 | WHERE order_meta.meta_key = '_order_total' |
| 505 | AND orders.post_status = 'wc-completed' |
| 506 | GROUP BY order_meta.meta_key |
| 507 | " ); |
| 508 | |
| 509 | if ( is_null( $gross_total ) ) { |
| 510 | $gross_total = 0; |
| 511 | } |
| 512 | |
| 513 | return array( |
| 514 | 'gross' => $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 | $min_max = $wpdb->get_row( " |
| 527 | SELECT |
| 528 | MIN( post_date_gmt ) as 'first', MAX( post_date_gmt ) as 'last' |
| 529 | FROM {$wpdb->prefix}posts |
| 530 | WHERE post_type = 'shop_order' |
| 531 | AND post_status = 'wc-completed' |
| 532 | ", ARRAY_A ); |
| 533 | |
| 534 | if ( is_null( $min_max ) ) { |
| 535 | $min_max = array( |
| 536 | 'first' => '-', |
| 537 | 'last' => '-', |
| 538 | ); |
| 539 | } |
| 540 | |
| 541 | return $min_max; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Make a request when opting out of tracker usage. |
| 546 | * |
| 547 | * @return void |
| 548 | */ |
| 549 | public static function opt_out_request() { |
| 550 | $body = array( |
| 551 | 'event' => 'opt-out', |
| 552 | 'email' => apply_filters( 'woocommerce_tracker_admin_email', get_option( 'admin_email' ) ), |
| 553 | 'url' => home_url(), |
| 554 | ); |
| 555 | wp_safe_remote_post( self::$api_url . 'event/', array( |
| 556 | 'method' => 'POST', |
| 557 | 'redirection' => 5, |
| 558 | 'httpversion' => '1.0', |
| 559 | 'blocking' => false, |
| 560 | 'headers' => array( 'user-agent' => 'WooCommerceTracker/' . md5( esc_url_raw( home_url( '/' ) ) ) . ';' ), |
| 561 | 'body' => wp_json_encode( $body ), |
| 562 | 'cookies' => array(), |
| 563 | ) ); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | WC_Tracker::init(); |
| 568 |