woocommerce / woocommerce-google-analytics-integration

WordPress plugin: Provides the integration between WooCommerce and Google Analytics.
http://wordpress.org/plugins/woocommerce-google-analytics-integration/
172 stars 69 forks source link

Uncaught Error: Call to a member function get_cart() on null #432

Closed BusinessBloomer closed 4 months ago

BusinessBloomer commented 4 months ago

Describe the bug:

Every night at around 2am my time I receive this non-blocking error:

Uncaught Error: Call to a member function get_cart() on null in /var/convesio/wordpress/wp-content/plugins/woocommerce-google-analytics-integration/includes/class-wc-abstract-google-analytics-js.php:193
Stack trace:
#0 /var/convesio/wordpress/wp-content/plugins/woocommerce-google-analytics-integration/includes/class-wc-abstract-google-analytics-js.php(68): WC_Abstract_Google_Analytics_JS->get_formatted_cart()
#1 /var/convesio/wordpress/wp-includes/class-wp-hook.php(324): WC_Abstract_Google_Analytics_JS->{closure}('')
#2 /var/convesio/wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#3 /var/convesio/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#4 /var/convesio/wordpress/wp-includes/general-template.php(3050): do_action('wp_head')
#5 /var/convesio/wordpress/wp-content/themes/storefront/header.php(18): wp_head()
#6 /var/convesio/wordpress/wp-includes/template.php(810): require_once('/var/convesio/w...')
#7 /var/convesio/wordpress/wp-includes/template.php(745): in /var/convesio/wordpress/wp-content/plugins/woocommerce-google-analytics-integration/includes/class-wc-abstract-google-analytics-js.php on line 193

Steps to reproduce:

I don't take any action, the error generates by itself every night.

Additional details:

`

WordPress Environment

WordPress address (URL): https://www.businessbloomer.com Site address (URL): https://www.businessbloomer.com WC Version: 8.9.1 REST API Version: ✔ 8.9.1 Action Scheduler Version: ✔ 3.7.4 Log Directory Writable: ✔ WP Version: 6.5.3 WP Multisite: – WP Memory Limit: 1 GB WP Debug Mode: – WP Cron: ✔ Language: en_US External object cache: –

Server Environment

Server Info: nginx/1.22.0 PHP Version: 7.4.32 PHP Post Max Size: 256 MB PHP Time Limit: 30 PHP Max Input Vars: 10000 cURL Version: 7.58.0 OpenSSL/1.1.1

SUHOSIN Installed: – MySQL Version: 5.5.5-10.6.8-MariaDB-1:10.6.8+maria~focal Max Upload Size: 256 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔

Database

WC Database Version: 8.9.1 WC Database Prefix: wp_ Total Database Size: 1138.01MB Database Data Size: 661.33MB Database Index Size: 476.68MB wp_woocommerce_sessions: Data: 2.02MB + Index: 0.08MB + Engine InnoDB wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_downloadable_product_permissions: Data: 0.20MB + Index: 0.45MB + Engine InnoDB wp_woocommerce_order_items: Data: 5.52MB + Index: 2.52MB + Engine InnoDB wp_woocommerce_order_itemmeta: Data: 42.58MB + Index: 42.13MB + Engine InnoDB wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_payment_tokenmeta: Data: 0.05MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_actions: Data: 0.41MB + Index: 0.45MB + Engine InnoDB wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_logs: Data: 1.52MB + Index: 0.34MB + Engine InnoDB wp_aelia_dismissed_messages: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_aelia_exchange_rates_history: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_affiliate_wp_affiliatemeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_affiliate_wp_affiliates: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_affiliate_wp_campaigns: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_affiliate_wp_connections: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_affiliate_wp_coupons: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_affiliate_wp_creativemeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_affiliate_wp_creatives: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_affiliate_wp_customermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_affiliate_wp_customers: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_affiliate_wp_custom_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_affiliate_wp_groups: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_affiliate_wp_notifications: Data: 0.06MB + Index: 0.02MB + Engine InnoDB wp_affiliate_wp_payouts: Data: 0.08MB + Index: 0.03MB + Engine InnoDB wp_affiliate_wp_referralmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_affiliate_wp_referrals: Data: 0.14MB + Index: 0.02MB + Engine InnoDB wp_affiliate_wp_rest_consumers: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_affiliate_wp_sales: Data: 0.05MB + Index: 0.02MB + Engine InnoDB wp_affiliate_wp_visits: Data: 0.14MB + Index: 0.02MB + Engine InnoDB wp_bp_option_tree: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_commentmeta: Data: 5.52MB + Index: 5.03MB + Engine InnoDB wp_comments: Data: 29.56MB + Index: 36.02MB + Engine InnoDB wp_ff_scheduled_actions: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_fluentform_entry_details: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_fluentform_forms: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_fluentform_form_analytics: Data: 5.02MB + Index: 0.00MB + Engine InnoDB wp_fluentform_form_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_fluentform_logs: Data: 0.17MB + Index: 0.00MB + Engine InnoDB wp_fluentform_submissions: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_fluentform_submission_meta: Data: 0.14MB + Index: 0.00MB + Engine InnoDB wp_fs_activities: Data: 0.06MB + Index: 0.00MB + Engine InnoDB wp_fs_attachments: Data: 0.05MB + Index: 0.00MB + Engine InnoDB wp_fs_conversations: Data: 0.36MB + Index: 0.00MB + Engine InnoDB wp_fs_data_metrix: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_fs_mail_boxes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_fs_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_fs_persons: Data: 0.06MB + Index: 0.00MB + Engine InnoDB wp_fs_products: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_fs_taggables: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_fs_tag_pivot: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_fs_tickets: Data: 0.48MB + Index: 0.00MB + Engine InnoDB wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_newsletter: Data: 5.52MB + Index: 1.81MB + Engine InnoDB wp_newsletter_autoresponder: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_newsletter_autoresponder_steps: Data: 1.52MB + Index: 1.52MB + Engine InnoDB wp_newsletter_emails: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_newsletter_sent: Data: 37.58MB + Index: 36.06MB + Engine InnoDB wp_newsletter_stats: Data: 17.52MB + Index: 15.03MB + Engine InnoDB wp_newsletter_user_logs: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_options: Data: 24.48MB + Index: 0.58MB + Engine InnoDB wp_postmeta: Data: 237.77MB + Index: 191.50MB + Engine InnoDB wp_posts: Data: 76.56MB + Index: 17.58MB + Engine InnoDB wp_prli_clicks: Data: 0.02MB + Index: 0.19MB + Engine InnoDB wp_prli_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_prli_links: Data: 0.11MB + Index: 0.25MB + Engine InnoDB wp_prli_link_metas: Data: 0.09MB + Index: 0.06MB + Engine InnoDB wp_redirection_404: Data: 49.08MB + Index: 14.13MB + Engine InnoDB wp_redirection_groups: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_redirection_items: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_redirection_logs: Data: 0.16MB + Index: 0.05MB + Engine InnoDB wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_terms: Data: 1.52MB + Index: 3.03MB + Engine InnoDB wp_term_relationships: Data: 1.52MB + Index: 1.52MB + Engine InnoDB wp_term_taxonomy: Data: 1.52MB + Index: 3.03MB + Engine InnoDB wp_tm_taskmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_tm_tasks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_usermeta: Data: 90.64MB + Index: 92.28MB + Engine InnoDB wp_users: Data: 5.52MB + Index: 5.55MB + Engine InnoDB wp_wcpdf_invoice_number: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcpdf_invoice_number_2021: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcpdf_invoice_number_2022: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcpdf_invoice_number_2023: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcpdf_packing_slip_number: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcs_payment_retries: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_customer_lookup: Data: 0.06MB + Index: 0.03MB + Engine InnoDB wp_wc_download_log: Data: 0.08MB + Index: 0.06MB + Engine InnoDB wp_wc_orders: Data: 0.02MB + Index: 0.11MB + Engine InnoDB wp_wc_orders_meta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_addresses: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_operational_data: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.05MB + Index: 0.06MB + Engine InnoDB wp_wc_order_stats: Data: 0.05MB + Index: 0.05MB + Engine InnoDB wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wpmailsmtp_debug_events: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_wpmailsmtp_tasks_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wt_iew_action_history: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wt_iew_cron: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wt_iew_ftp: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wt_iew_mapping_template: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yoast_indexable: Data: 1.52MB + Index: 0.48MB + Engine InnoDB wp_yoast_indexable_hierarchy: Data: 0.09MB + Index: 0.17MB + Engine InnoDB wp_yoast_migrations: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_yoast_primary_term: Data: 0.08MB + Index: 0.09MB + Engine InnoDB wp_yoast_seo_links: Data: 1.52MB + Index: 3.03MB + Engine InnoDB wp_yoast_seo_meta: Data: 3.52MB + Index: 0.00MB + Engine InnoDB

Post Type Counts

attachment: 3002 certificate: 9 certificate_template: 1 class: 14 course: 7 email-template: 5 lesson: 213 nav_menu_item: 33 oembed_cache: 354 option-tree: 9 page: 59 popup: 1 popup_theme: 1 post: 864 pretty-link: 369 product: 65 product_variation: 24 question: 29 quiz: 126 revision: 1977 safecss: 1 sg_optimizer_jobs: 8 shop_coupon: 16671 shop_order: 49564 shop_order_refund: 89 shop_subscription: 747 user_request: 19 wc_zapier_feed: 1 wp-call-to-action: 1 wp_block: 13 wp_global_styles: 1 wp_navigation: 4

Security

Secure connection (HTTPS): ✔ Hide errors from visitors: ✔

Active Plugins (25)

AffiliateWP: by AffiliateWP – 2.24.5 AffiliateWP - Allowed Products: by Sandhills Development LLC – 1.3

Convesio Caching: by Convesio – 3.7.0 Disable Bloat for WordPress & WooCommerce: by Disable Bloat – 3.4.8 Duplicate Page: by mndpsingh287 – 4.5.3 Enable Media Replace: by ShortPixel – 4.1.5 Fluent Support: by WPManageNinja LLC – 1.7.90 Fluent Forms: by Contact Form - WPManageNinja LLC – 5.1.18 Metorik Helper: by Metorik – 1.7.1 Microsoft Clarity: by Microsoft – 0.9.4 Pretty Links: by Pretty Links – 3.6.6 Redirection: by John Godley – 5.4.2 Simple Cloudflare Turnstile: by Elliot Sowersby RelyWP – 1.26.2

SyntaxHighlighter Evolved: by Alex Mills (Viper007Bond) – 3.7.0 Two Factor Authentication: by David Anderson original plugin by Oskar Hane and enhanced by Dee Nutbourne – 1.14.17

Spectra: by Brainstorm Force – 2.13.3 User Switching: by John Blackbourn & contributors – 1.7.3 WooCommerce Fattureincloud: by Woofatture – 2.6.3 WooCommerce Stripe Gateway: by WooCommerce – 8.3.1 Google Analytics for WooCommerce: by WooCommerce – 2.0.7 PDF Invoices & Packing Slips for WooCommerce: by WP Overnight – 3.8.2 WooCommerce: by Automattic – 8.9.1 Yoast SEO: by Team Yoast – 22.8 WP Mail SMTP: by WP Mail SMTP – 4.0.1 XPoster - Share to X and Mastodon: by Joseph C Dolson – 4.2.4

Inactive Plugins (2)

Better Search Replace: by WP Engine – 1.4.7 Query Monitor: by John Blackbourn – 3.16.3

Must Use Plugins (1)

WP Auto Login: by Team Convesio – 1.2

Settings

API Enabled: – Force SSL: – Currency: USD ($) Currency Position: left Thousand Separator: , Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: bundle (bundle) external (external) grouped (grouped) simple (simple) subscription (subscription) variable (variable) variable subscription (variable-subscription) yith_bundle (yith_bundle)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5)

Connected to WooCommerce.com: ✔ Enforce Approved Product Download Directories: – HPOS feature enabled: – Order datastore: WC_Order_Data_Store_CPT HPOS data sync enabled: –

Logging

Enabled: ✔ Handler: Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2 Retention period: 30 days Level threshold: – Log directory size: 3 MB

WC Pages

Shop base: #4731 - /shop/ Cart: #195094 - /cart/ Checkout: #853 - /checkout/ My account: #854 - /my-account/ Terms and conditions: #73881 - /terms-and-conditions/

Theme

Name: storefront-bbloomer Version: 7.5.20240409 Author URL: Child Theme: ✔ Parent Theme Name: Storefront Parent Theme Version: 4.6.0 Parent Theme Author URL: https://woocommerce.com/ WooCommerce Support: ✔

Templates

Overrides: –

Admin

Enabled Features: activity-panels analytics product-block-editor coupons core-profiler customize-store customer-effort-score-tracks import-products-task experimental-fashion-sample-products shipping-smart-defaults shipping-setting-tour homescreen marketing mobile-app-banner navigation onboarding onboarding-tasks product-variation-management product-virtual-downloadable product-external-affiliate product-grouped product-linked product-pre-publish-modal product-custom-fields remote-inbox-notifications remote-free-extensions payment-gateway-suggestions shipping-label-banner subscriptions store-alerts transient-notices woo-mobile-welcome wc-pay-promotion wc-pay-welcome-page

Disabled Features: minified-js new-product-management-experience settings async-product-editor-category-field launch-your-store

Daily Cron: ✔ Next scheduled: 2024-06-04 15:44:56 +02:00 Options: ✔ Notes: 9 Onboarding: completed

Action Scheduler

Complete: 702 Oldest: 2024-05-04 22:50:07 +0200 Newest: 2024-06-04 13:29:48 +0200

Failed: 160 Oldest: 2023-02-17 12:48:04 +0100 Newest: 2024-05-27 15:21:44 +0200

Pending: 10 Oldest: 2024-06-04 23:02:48 +0200 Newest: 2025-01-01 00:00:01 +0100

Status report information

Generated at: 2024-06-04 16:36:33 +02:00 `

martynmjones commented 4 months ago

Hey @BusinessBloomer, thanks for the report!

Every night at around 2am my time I receive this non-blocking error:

Given the specific time the errors are being logged every night it sounds like this is related to a cron job running on your site.

WooCommerce doesn't instantiate WC_Cart for requests if they come from a cronjob which is likely the cause of this error. Google Analytics for WooCommerce hooks into wp_head before accessing the cart so at that point it should always be available but that's obviously not the case here.

I'm not able to say exactly why this may be happening on your site but it sounds like something in the cron may be loading the frontend of the website or triggering front-end hooks.

Although I'm not able to reproduce the error using site configuration, I have opened a pull request to check the cart object is available before accessing it (#435). When that's merged and released you should see the errors go away after updating.