Skip to content

Header cart icon fatals when the WooCommerce cart object is null #4555

Description

@pirate-bot

Summary

The Header Footer Grid cart icon can terminate a frontend request when WooCommerce is loaded but its cart object is unavailable. The header is expected to render without a fatal error in this state; instead, rendering the configured cart component calls a method on null. This prevents the affected page response from completing.

Customer context

Product / area: Neve Header Footer Grid, WooCommerce cart icon
Version: Neve 4.2.10
Environment: WordPress 7.0.2, PHP 8.2.30, frontend request
Integration / third party: WooCommerce; exact WooCommerce version not reported
Reported error / symptom: Error: Call to a member function get_cart_contents_count() on null
Impact: 8 fatal occurrences on 1 production site in the telemetry window

Reproduction notes

  1. Configure the Neve Header Footer Grid to render the WooCommerce cart icon.
  2. Trigger a frontend request in a state where WooCommerce is loaded but WC()->cart is null.
  3. Header rendering reaches component-cart-icon.php and fatals at the empty-cart count read.

Status: confirmed in production telemetry with 8 occurrences on one site and confirmed against tag v4.2.10; the exact request condition that leaves the cart null is not available for local reproduction.

Diagnosis

Conclusion

The defect is confirmed by production crash telemetry and repository inspection. The representative trace ends at the first cart-count read in the header cart template, where WC()->cart was null. Neve 4.2.10 contains the same unconditional dereference at the reported location, while component availability only establishes that the WooCommerce class is loaded.

Where this likely occurs

  • User-visible surface: frontend header rendering when the Header Footer Grid cart icon is configured.
  • header-footer-grid/templates/components/component-cart-icon.php — template scope, line 21: unconditionally calls WC()->cart->get_cart_contents_count() to derive the empty-cart class; line 54 contains a second count read that is reachable if the first succeeds.
  • header-footer-grid/Core/Components/CartIcon.phpCartIcon::is_active() lines 127–129 checks only class_exists( 'WooCommerce', false ); CartIcon::render_component() lines 279–281 loads the template without a cart-object check.
  • header-footer-grid/loader.php — component registration lines 18–20 is likewise conditional only on the WooCommerce class.
  • Git history: commit 7339cdc89140011ca447b085816142853a434e77 introduced the line-21 count read in 2020. Tag v4.2.10 retains the unconditional dereference, and the inspected checkout is at v4.2.10.

Engineering notes

The trace confirms a frontend state where WooCommerce itself was loaded but WC()->cart was null. The available plugin-only/theme checkout does not establish which WooCommerce lifecycle, request variant, or third-party interaction produced that state. The failure happens before the template emits the cart markup, so the frontend response is interrupted. The reported location is Neve product code rather than the bundled Themeisle SDK.

Test coverage status

e2e-tests/specs/woocommerce/header-mini-cart.spec.ts covers normal shop and product-page rendering, cart navigation, count updates, and mini-cart styling. Those scenarios use an initialized cart and do not cover frontend rendering while WC()->cart is null. No relevant PHPUnit coverage was found during inspection.

What to verify or explore next

  • Reproduce a frontend header render with the cart component configured while WooCommerce is loaded and WC()->cart remains null.
  • Check whether WordPress 7.0.2 or the production site's request type affects WooCommerce cart initialization timing.
  • Run e2e-tests/specs/woocommerce/header-mini-cart.spec.ts for normal initialized-cart compatibility.
  • Exercise empty and populated carts across link, dropdown, and off-canvas cart styles after reproducing the null-cart state.

Unknowns / follow-up

  • The WooCommerce version, request URL type, active extensions, and initialization sequence from the affected site were not captured.
  • The available evidence does not identify why the production request reached header rendering before a cart object was available.

Confidence

Confidence: 98/100

Production telemetry captured eight identical frontend fatals at an exact Neve source line, and the affected release directly dereferences the nullable WooCommerce cart object without an object guard. The current issue search found no matching open or closed report.

Crash telemetry

Occurrences 8
Distinct sites 1
First seen 2026-07-29 20:26 UTC
Last seen 2026-07-29 20:26 UTC
Crash location product:header-footer-grid/templates/components/component-cart-icon.php:21
Request context frontend
Inside Themeisle SDK no
Product versions 4.2.10
WP versions 7.0.2
PHP versions 8.2.30
SDK versions 3.3.59

Source: automated crash report — neve, fingerprint f75f57bcd89182237cd758e83e6f1e86
Generated by bug-report-triage (ID: bug-report-triage_6a6b3c2d51be99.82749848)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions