Skip to content

Commit a5b0d2e

Browse files
authored
WooCommerce Analytics: Fix WC_Tracks class not found fatal error (#45330)
* Fix WC_Tracks class not found fatal error * Fix warnings * Add changelog
1 parent e3c1028 commit a5b0d2e

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
WC_Tracks class not found fatal error and key undefined warnings

projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ public static function get_properties( $event_name, $event_properties ) {
182182
'landing_page' => $session_details['landing_page'] ?? null,
183183
'is_engaged' => $session_details['is_engaged'] ?? null,
184184
'ui' => $blog_user_id,
185-
'blog_id' => $blog_details['blog_id'],
186-
'store_id' => $blog_details['store_id'],
187-
'url' => $blog_details['url'],
188-
'woo_version' => $blog_details['wc_version'],
185+
'blog_id' => $blog_details['blog_id'] ?? null,
186+
'store_id' => $blog_details['store_id'] ?? null,
187+
'url' => $blog_details['url'] ?? null,
188+
'woo_version' => $blog_details['wc_version'] ?? null,
189189
'wp_version' => get_bloginfo( 'version' ),
190190
'store_admin' => count( array_intersect( array( 'administrator', 'shop_manager' ), wp_get_current_user()->roles ) ) > 0 ? 1 : 0,
191191
'device' => wp_is_mobile() ? 'mobile' : 'desktop',

projects/packages/woocommerce-analytics/src/class-woocommerce-analytics.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ public static function should_track_store() {
9191
return false;
9292
}
9393

94+
// Ensure the WC Tracks classes exist.
95+
if ( ! class_exists( 'WC_Tracks' ) ) {
96+
if ( ! defined( 'WC_ABSPATH' ) || ! file_exists( WC_ABSPATH . 'includes/tracks/class-wc-tracks.php' ) ) {
97+
return false;
98+
}
99+
100+
include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks.php';
101+
include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks-event.php';
102+
include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks-client.php';
103+
}
104+
94105
// Tracking only Site pages.
95106
if ( is_admin() || wp_doing_ajax() || wp_is_xml_request() || is_login() || is_feed() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
96107
return false;

0 commit comments

Comments
 (0)